Re:Stop requiring only one assertion per unit test: Multiple...
by masklinn on Saturday November 05, 2022 @08:21AM
(#33480753)
That seems like it'd easily get confusing, when the assertions are dependent. Which is often the case e.g. if the list is empty, testing the properties of the first item make no sense.
[ Parent
| on HN ]
Re:Stop requiring only one assertion per unit test: Multiple...
by jmillikin on Saturday November 05, 2022 @08:31AM
(#33480797)
That's why the first check is a hard assertion (returning on error), and the others are soft (continuing on error).
If the list is empty, then the log will contain one error about the length being zero. If the list has one item but it has the wrong properties, the log will contain two errors.
Re:Stop requiring only one assertion per unit test: Multiple...
by masklinn on Saturday November 05, 2022 @08:36AM
(#33480826)
> That's why the first check is a hard assertion (returning on error), and the others are soft (continuing on error).
See that's so completely unclear I utterly missed that there were two different calls there. Doesn't exactly help that the functions are the exact same length, and significantly overlap in naming.
Re:Stop requiring only one assertion per unit test: Multiple...
by TeMPOraL on Saturday November 05, 2022 @09:29AM
(#33481267)
That's just a matter of familiarity, though. And if you make a mistake, you'll discover it the first time the test fails - either you'll see too little output, or you'll see the test throw an exception or crash.
Re:Stop requiring only one assertion per unit test: Multiple...
by HereBeBeasties on Saturday November 05, 2022 @09:36AM
(#33481337)
I bet if it were in monospace and you were reading code in context rather than on HN you'd have noticed.
That said, NUnit has much better syntax for this, where you put parallel/multiple assertions like this in an explicit block together: https://docs.nunit.org/articles/nunit/writing-tests/assertio...
Much less boilerplate duplication in the actual test framework, too.