Friday, 7 January 2011

Useful NUnit attributes

I can never remember the various NUnit attributes I find useful (other than the basics like TestFixture, Test, SetUp, TearDown and ExpectedException) so here’s a quick aide-mémoire (NB: this is not a complete list by any means):

Attribute Description
CombinatorialAttribute Used on a test to specify that NUnit should generate test cases for all possible combinations of the individual data items provided.

ExplicitAttribute

Causes a test or test fixture to be ignored unless it is explicitly selected for running.

RandomAttribute

Used to specify a set of random values to be provided for an individual parameter of a parameterized test method.
RangeAttribute Used to specify a range of values to be provided for an individual parameter of a parameterized test method.

SequentialAttribute

used on a test to specify that NUnit should generate test cases by selecting individual data items provided for the parameters of the test, without generating additional combinations.
TestCaseAttribute Serves the dual purpose of marking a method with parameters as a test method and providing inline data to be used when invoking that method.
TestCaseSourceAttribute Used on a parameterized test method to identify the property, method or field that will provide the required arguments.
ValuesAttribute Used to specify a set of values to be provided for an individual parameter of a parameterized test method.