The default rule when writing tests is ‘one test, one assert’. There are multiple reasons why this is a good idea:
- It becomes very clear what your test is doing and what the success or failure condition is
- If there are multiple asserts in your test, the test will fail on the first assert that returns false. The other assertions will never be validated.
However this sometimes lead to duplication where you are writing the same test multiple times to assert different aspects.
In NUnit you can avoid the second reason by using ‘Assert.Multiple()’.
NUnit will store any failures encountered in the Multiple block and report all of them together. If multiple asserts failed, then all will be reported.