79624762

Date: 2025-05-16 08:22:05
Score: 0.5
Natty:
Report link

I know this is an old question but I think it is still relevant and I don't believe the question is worth the down vote it got. It seems like the "Should..." phrasing is still very prevalent when writing unit tests. And in my opinion it is an incorrect format:

Apart from the correct observation by @Estus, that is pollutes the test results, it also conveys an intent of uncertainty.

When you test functionality, you do it because you want the functionality to actually work. It has to work or it is a hard error. So using a more deterministic language, where you don't use "should" conveys this intent. Using "should" indicates that you are unsure if it works or not, while writing the phrase in a more commanding tone, you convey certainty and determinism.

continuing the examples of @Estus:

- Should have a button
- Should do a request

vs

- Has a button
- Requests the data

In the first examples, the sentiment you get when reading is of uncertainty. You timidly don't really want to take stance and say that this is how it works. It works... maybe... if you want to. I guess it can be argued that a test is uncertain by nature, but in general, what you want is to verify is that it does what you want it to do. No question. This is how it has to work. Otherwise it is a failure. Do or die! Which is better conveyed by the counter examples below.

So, in short, I think the use of "should" is not precise enough and should (correct usage of the word to convey that you do how you see fit ;)) not be used, but in the end it is a question of taste as well as it has no real impact on the final test.

Reasons:
  • RegEx Blacklisted phrase (2): down vote
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Estus
  • High reputation (-1):
Posted by: Tokimon