Added in NUnit 3.13
FixtureLifeCycleAttribute is used to indicate that an instance for a test fixture or all test fixtures in an assembly should be constructed for each test within the fixture or assembly.
This attribute may be applied to a test fixture (class) or to a test assembly. It is useful in combination with the Parallelizable Attribute so that a new instance of a test fixture is constructed for every test within the test fixture. This allows tests to run in isolation without sharing instance fields and properties during parallel test runs. This make running parallel tests easier because it is easier to make your tests thread safe.
This attribute can be applied to classes or to the entire test assembly. If applied to an assembly, it may be overridden at the class level.
The constructor of
FixtureLifeCycleAttribute takes a
LifeCycle attribute to indicate if a single instance of a test fixture should be created for all tests or if a new instance should be created for each test.
||A single instance is created and shared for all test cases|
||A new instance is created for each test case|
OneTimeTearDownmethods must be static, and each are only called once. This is required so that the setup or teardown methods do not access instance fields or properties that are reset for every test.
LifeCycle.InstancePerTestCase, a class's constructor will be called before every test is executed and
IDisposabletest fixtures will be disposed after the test is finished.
Orderattribute is respected.