-
Notifications
You must be signed in to change notification settings - Fork 158
SetUp and TearDown
-
SetUpAttribute is now used exclusively for per-test setup.
-
TearDownAttribute is now used exclusively for per-test teardown.
-
OneTimeSetUpAttribute is used for one-time setup per test-run. If you run n tests, this event will only occur once.
-
OneTimeTearDownAttribute is used for one-time teardown per test-run. If you run n tests, this event will only occur once
-
SetUpFixtureAttribute continues to be used as at before, but with changed method attributes.
TestFixture | SetUpFixture | |
---|---|---|
OneTimeSetUp | Supported | Supported |
OneTimeTearDown | Supported | Supported |
TestFixtureSetUp | Deprecated | Not Allowed |
TestFixtureTearDown | Deprecated | Not Allowed |
SetUp | Supported | Not Allowed |
TearDown | Supported | Not Allowed |
Multiple SetUp, OneTimeSetUp, TearDown and OneTimeTearDown methods may exist within a class.
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.
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.
public class BaseClass
{
[SetUp]
public void BaseSetUp() { ... } // Exception thrown!
[TearDown]
public void BaseTearDown() { ... }
}
[TestFixture]
public class DerivedClass : BaseClass
{
[SetUp]
public void DerivedSetUp() { ... }
[TearDown]
public void DerivedTearDown() { ... }
[Test]
public void TestMethod() { ... }
}
Execution will proceed as follows:
- BaseSetUp
- BaseTearDown
rather than
- BaseSetUp
- DerivedTearDown
- BaseTearDown
See also: SetUp and TearDown Changes
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0
-
NUnit
-
Release Notes
-
License
- Getting Started
- Writing Tests
- Running Tests
- Extending NUnit
- Technical Notes
-
Release Notes
- NUnit Xamarin Runners
- VS Test Adapter
- VS Test Generator
- NUnit Analyzers