NUnit attributes

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.

public class ObjectUnitTests
    public void BeforeAnyTesting() {...}

    public void BeforeEachTest() {...}

    public void AUnitTest() 
        // Arrange
        // Act

        // Assert

    public void DontRunThisTestEver() {...}

    public void UserMustManuallyRequestThisTest() {...}

    public void AfterEachTest() {...}

    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”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s