Test case
Test case is a self-validating programmer test that can be automatically discovered and executed independently of other test cases by a test runner.
Test Suite
A test suite is a collection of test cases or other test suites. The relationship between test cases and test suites is described by the Composite[2] pattern.
Test Fixture
A test fixture is a group of test cases sharing a common set of run-time resources.
Tests and Test Fixtures
One of the features of the NUnit Framework is its use of custom attributes. Attributes in .NET are the standard mechanisms to extend metadata about run- time entities. In this case, the run-time entities of interest are as follows:
Test classes are the classes that contain test code; each test assembly has to have at lease one test class.
Test methods are test cases; each test method represents a single test case that can be run independently of other test cases.
Using SetUp/TearDown Attributes
In the definition of a test fixture that we gave earlier, we said that tests in a test fixture share a common set of run-time resources. These common run-time resources may need to be acquired and initialized in a certain way before a test is executed and released or cleaned up after the test is completed. NUnit supports this common initialization/cleanup process using two additional custom attributes: SetUp and TearDown.
Using ExpectedException
You can use this attribute to indicate that an exception of a particular type is expected during the execution of the test method. If the method completes without throwing the expected exception, the test fails. Using this attribute helps in writing programmer tests that verify boundary conditions.
Using the Ignore Attribute
the Ignore attribute, you can keep the tests but not execute them.
The Ignore attribute can be attached to either an individual test method or an entire test class (TestFixture).
Using TestFixtureSetUp/TestFixtureTearDown
NUnit has a pair of attributes that are similar to the SetUp/TearDown attributes discussed earlier: TestFixtureSetUp/TestFixtureTearDown. As their names suggest, these attributes are used to mark methods that initialize/release resources once for the entire test fixture.
Test Life-Cycle Contract
FixtureSetUp
SetUp
Test 1
TearDown
SetUp
Test 2
TearDown
FixtureTearDown