The general rule is “assert logically”, which means one is allowed to create multiple Assert.xxx statements in a single unit test.

However, this technique leaves open the issue of quickly discovering why did a test fail.

Here are some links to help with having single asserts per test:

http://blog.drorhelper.com/2011/02/multiple-asserts-done-right.html

https://xunit.github.io/docs/shared-context.html

Important information when using XUnit: a new instance of the test class is created for every test that is run (the code in the constructor is executed for each run test, each run test receives a clean copy of the ‘context object’).

The cleanup code is to be implemented in the Dispose method.

Advertisements