7 ms·
I prefer that the test name doesn’t say “should”. Instead, I like when it states the expected behaviour as though it was a fact. “Should” to me is too weak. N
by codetrotter 4y ago
I prefer that the test name doesn’t say “should”. Instead, I like when it states the expected behaviour as though it was a fact.
“Should” to me is too weak.
No, it’s not just “should”. It does. And if it doesn’t then either the implementation is broken, or the test is bad.
“Should” has connotations for me of something that we want but which we don’t require.
Therefore, I don’t use the word “should” in my test names.
Instead of “should have length 256”, I say “has length 256”.
- p10r 4y agoI'm doing exactly the same. Another added benefit of that is that you save some length in the test name, which can be quite helpful in certain scenarios.
- gjvc 4y agoyes. depending on who I'm talking to about this sort of thing I refer them to https://www.ietf.org/rfc/rfc2119.txt https://www.ietf.org/rfc/rfc2119.txt to demonstrate the importance.
- kkoncevicius 4y agoI usually do the same but arrived at this by using a mental prefix of "test that". As in: "this test tests that" input has length 256 Since the prefix would be equal for all the tests only the last part becomes the name.
- dejj 4y agoI realized that all my tests in fact “Shall test that X holds.”, tautologically. Now I consider that style boilerplate, and just write “X shall hold.”
- hprotagonist 4y agooh i like “test that”.
- ta1243 4y agoassert?
- raydiatian 4y ago“Shall” is another term I’ve seen used in larger orgs where teams literally craft test requirements as a gigantic database. “Shall” is for things that must be satisfied, “should” is for softer requirements and is rarely used.
- wongarsu 4y agoAbsolutely. From RFC2119: > MUST This word, or the terms "REQUIRED" or "SHALL", mean that the definition is an absolute requirement of the specification. >SHOULD This word, or the adjective "RECOMMENDED", mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.
- npsomaratna 4y agoThank you for posting this. At first, I thought your reply was an attempt at sarcasm—but on searching, I found the relevant RFC. Just shows that even after 30+ years of programming, there is so much that I don't know.
- blowski 4y agoThe British Highway Code uses similar terminology. Breaking a “must” rule is a punishable offence, where “should” rules are just for advice.
- karmelapple 4y agoThis is a common standard in aerospace requirements documents. Join the world of needing to make the FAA happy and your vocabulary will change to incorporate shall, will, must, and others in a more discerning manner.
- silveroriole 4y agoAbsolutely. I tell people this constantly. If you write a test that says “it should have length 256”, that’s an assertion on the design intention, not on the actual functioning of the code. “It should have length 256” == true as soon as the product guy says it should. “It has length 256” == true when I’ve written the code to make it have length 256.