Back to Nunit

Attributes

docs/articles/nunit/writing-tests/attributes.md

latest6.8 KB
Original Source

Attributes

NUnit uses custom attributes to identify tests. All NUnit attributes are contained in the NUnit.Framework namespace. Each source file that contains tests must include a using statement for that namespace and the project must reference the framework assembly, nunit.framework.dll.

This table lists all the attributes supported by NUnit.

AttributeUsage
Apartment AttributeIndicates that the test should run in a particular apartment.
Author AttributeProvides the name of the test author.
CancelAfter AttributeProvides a timeout value in milliseconds for test cases.
Category AttributeSpecifies one or more categories for the test.
Combinatorial AttributeGenerates test cases for all possible combinations of the values provided.
Culture AttributeSpecifies cultures for which a test or fixture should be run.
Datapoint AttributeProvides data for Theories.
DatapointSource AttributeProvides data for Theories.
DefaultFloatingPointTolerance AttributeIndicates that the test should use the specified tolerance as default for float and double comparisons.
Description AttributeApplies descriptive text to a Test, TestFixture or Assembly.
Explicit AttributeIndicates that a test should be skipped unless explicitly run.
FixtureLifeCycle AttributeSpecifies the lifecycle of a fixture allowing a new instance of a test fixture to be constructed for each test case. Useful in situations where test case parallelism is important.
Ignore AttributeIndicates that a test shouldn't be run for some reason.
LevelOfParallelism AttributeSpecifies the level of parallelism at assembly level.
MaxTime AttributeSpecifies the maximum time in milliseconds for a test case to succeed.
NonParallelizable AttributeSpecifies that the test and its descendants may not be run in parallel.
NonTestAssembly AttributeSpecifies that the assembly references the NUnit framework, but that it does not contain tests.
OneTimeSetUp AttributeIdentifies methods to be called once prior to any child tests.
OneTimeTearDown AttributeIdentifies methods to be called once after all child tests.
Order AttributeSpecifies the order in which decorated test should be run within the containing fixture or suite.
Pairwise AttributeGenerate test cases for all possible pairs of the values provided.
Parallelizable AttributeIndicates whether test and/or its descendants can be run in parallel.
Platform AttributeSpecifies platforms for which a test or fixture should be run.
Property AttributeAllows setting named properties on any test case or fixture.
Random AttributeSpecifies generation of random values as arguments to a parameterized test.
Range AttributeSpecifies a range of values as arguments to a parameterized test.
Repeat AttributeSpecifies that the decorated method should be executed multiple times.
RequiresThread AttributeIndicates that a test method, class or assembly should be run on a separate thread.
Retry AttributeCauses a test to be rerun if it fails, up to a maximum number of times.
Sequential AttributeGenerates test cases using values in the order provided, without additional combinations.
SetCulture AttributeSets the current Culture for the duration of a test.
SetUICulture AttributeSets the current UI Culture for the duration of a test.
SetUp AttributeIndicates a method of a TestFixture called just before each test method.
SetUpFixture AttributeMarks a class with one-time setup or teardown methods for all the test fixtures in a namespace.
SingleThreaded AttributeMarks a fixture that requires all its tests to run on the same thread.
TearDown AttributeIndicates a method of a TestFixture called just after each test method.
Test AttributeMarks a method of a TestFixture that represents a test.
TestCase AttributeMarks a method with parameters as a test and provides inline arguments.
TestCaseSource AttributeMarks a method with parameters as a test and provides a source of arguments.
TestFixture AttributeMarks a class as a test fixture and may provide inline constructor arguments.
TestFixtureSetup AttributeDeprecated synonym for OneTimeSetUp Attribute.
TestFixtureSource AttributeMarks a class as a test fixture and provides a source for constructor arguments.
TestFixtureTeardown AttributeDeprecated synonym for OneTimeTearDown Attribute.
TestOf AttributeIndicates the name or Type of the class being tested.
Theory AttributeMarks a test method as a Theory, a special kind of test in NUnit.
Timeout AttributeProvides a timeout value in milliseconds for test cases.
Values AttributeProvides a set of inline values for a parameter of a test method.
ValueSource AttributeProvides a source of values for a parameter of a test method.