Edit: There is now an updated version of this reference here
This is one of those entries for something which should be easy to remember, but, alas, I constantly forget: which NUnit attributes should I decorate my unit test classes with.
So, here is a cheat-sheet for myself. Perhaps, someday, I may expand this entry into a full reference.
[TestFixture]
public class ObjectUnitTests
{
[TestFixtureSetUp][OneTimeSetup]
public void BeforeAnyTesting() {...}
[SetUp]
public void BeforeEachTest() {...}
[Test]
[Category("AlwaysRuns")]
public void AUnitTest()
{
// Arrange
...
// Act
...
// Assert
...
}
[Ignore]
[Category("NotAlwaysRuns")]
public void DontRunThisTestEver() {...}
[Explicit]
[Category("NotAlwaysRuns")]
public void UserMustManuallyRequestThisTest() {...}
[TearDown]
public void AfterEachTest() {...}
[TestFixtureTearDown][OneTimeTearDown]
public void AfterAllTesting() {...}
}
Note: As of NUnit 3, [TestFixtureSetup] and [TestFixtureTearDown] are replaced by [OneTimeSetup] and [OneTimeTearDown] – which does make it a little simpler to remember the usages.
One thought on “NUnit attributes”