NUnit allows you to bootstrap individual tests through the SetUp and TearDown attributes. I typically try to keep my test classes clean and one way to do this is by moving logic to a test base class.
NUnit will walk through the inheritance tree and call all Setup and TearDown methods. Setup methods (both types) are called on base classes first, then on derived classes. If any setup method throws an exception, no further setups are called.
Something I noticed in the documentation:
Teardown methods (again, both types) are called on derived classes first, then on the base class. The teardown methods at any level in the inheritance hierarchy will be called only if a setup method at the same level was called. The following example is illustrates the difference.
So if you have a test structure like below, only the base SetUp and TearDown are called:
This is a breaking change from NUnit 2.x and something to be aware of…