5 ms·
Is it weird that not only have I never heard of the "rule" this post argues against, but I can't even conceive of a code structure where it would make sense? H
by jmillikin 4y ago
Is it weird that not only have I never heard of the "rule" this post argues against, but I can't even conceive of a code structure where it would make sense?
How would a test suite with one assertion per test work? Do you have all the test logic in a shared fixture and then dozens of single-assertion tests? And does that rule completely rule out the common testing pattern of a "golden checkpoint"?
I tried googling for that rule and just came up with page after page of people arguing against it. Who is for it?
- littlecranky67 4y ago> Is it weird that not only have I never heard of the "rule" this post argues against This "rule" is known mostly because it is featured in the "Clean Code" book by Robert C. Martin (Uncle Bob). You should have heard of it ;)
- TeMPOraL 4y agoPerhaps the author is better off not having heard of it then, and by implication, not having read "Clean Code" in the first place. The book is full of anti-patterns.
- Kwpolska 4y agoThe book is so full of bad advice I'm not surprised this "rule" comes from there as well.
- teddyh 4y agoAs MikeDelta reports¹, the book doesn’t actually say that. I’ve come to learn to completely disregard any non-specific criticism of that book (and its author). There is apparently a large group of people who hate everything he does and also, seemingly, him personally. Everywhere he (or any of his books) is mentioned, the haters come out, with their vague “it’s all bad” and the old standard “I don’t know where to begin”. Serious criticism can be found (if you look for it), and the author himself welcomes it, but the enormous hate parade is scary to see. 1. https://news.ycombinator.com/item?id=33480517 https://news.ycombinator.com/item?id=33480517
- jmillikin 4y agoHeard of it, but never read it. Looking at the Amazon listing and a third-party summary[0] it seems to be the sort of wool-brained code astrology that was popular twenty years ago when people were trying to push "extreme programming" and TDD. [0] https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988cf8d29 https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988c...
- willsmith72 4y agoWait what's wrong with XP and TDD? Where I'm from those are absolutely considered best practice for most situations
- teddyh 4y agoWhere in that book is the rule stated? I ask because I have heard the author explicitly state that multiple assertions are fine (using essentially the same explanation as TrianguloY did in this comment: https://news.ycombinator.com/item?id=33480120 https://news.ycombinator.com/item?id=33480120).
- MikeDelta 4y agoChapter 9 talks about unit tests and there is a paragraph called 'Single Assert per Test', where he says it is a good concept but that he is not afraid to put more asserts in his tests. That paragraph is followed by 'Single Concept per Test' where he starts with: 'Perhaps a better rule is that we want to test a single concept per test.' So, technically he doesn't say it.
- ThunderSizzle 4y agoThat maps better with the lectures I've seen of him on YouTube, and I concur with it. When I first wrote tests years ago, I would try to test everything in one test function. I think juniors have a tendency to do that in functions overall - it's par to see 30-100+ line functions that might be doing just a little too much on their own, and test functions are no different.
- daviddever23box 4y agoIt feels as if folks are splitting hairs where a haircut (or at least a half-hearted attempt at grooming) is required. Use good judgment, and do not blindly follow "rules" without understanding their effects.
- matthews2 4y agoAre there any "rules" in Clean Code that don't need to be disregarded and burned? https://qntm.org/clean https://qntm.org/clean
- pydry 4y agoThere's plenty of sensible advice in there it's just that he argues for the sensible stuff and the idiotic stuff with equal levels of conviction and if you are junior you aren't going to be able to distinguish them. It would be easier if it were all terrible advice.
- stephencanon 4y agoFortunately you readily find the good advice in lots of other places, so you can simply ignore that book.
- deleted 4y ago[deleted]
- mollerhoj 4y agoI believe theres a rubocop that checks for it: https://docs.rubocop.org/rubocop-minitest/cops_minitest.html#minitestmultipleassertions https://docs.rubocop.org/rubocop-minitest/cops_minitest.html...
- raverbashing 4y agoNothing like machine-enforced nitpicking of the worse kind But even this rule/plugin has a default value of 3 which is a more sane value.
- deleted 4y ago[deleted]