ne2dmar
ne2dmar

Reputation: 534

SetUp and TearDown for entire run in Nunit?

I want to use NUnit to run GUI / integration tests. What I would like to do is to initialize some custom reporting (from GUI-testing framework we use) before all tests and to run export of the reports after the whole suite has been run.

Is there some "super" setup method or practice to solve this problem?

I thought about running a special "TestFixture" before and after all other tests, but that is quite poor idea. Another way would be to run some scripts afterwards but that doesn't solve the problem with pre-run initialization of logging.

Upvotes: 3

Views: 1428

Answers (1)

Chris Missal
Chris Missal

Reputation: 6123

You can use the [SetUpFixture] attribute to instantiate a class before all tests are run. The constructor of this class will be called first. If this class implements IDisposable, then the Dispose method will be called after all tests are run.

Here's an example:

[SetUpFixture]
public class IntegrationSetUpFixture : IDisposable
{
    public IntegrationSetUpFixture()
    {
        // runs before all tests
    }

    public void Dispose()
    {
        // runs after all tests
    }
}

Upvotes: 3

Related Questions