I've got a bunch of tests in NUnit which create garbage data on the filesystem (bad, I know, but I have little control over this). Currently we have a cleanup tool that removes these temporaries and such, but I'd like to be able to run that cleanup tool automatically. I'd have to be able to run it after all tests have finished running. I have similar checking that I'd like to do at the beginning, to ensure that there are none of these temporaries left from previous runs that might change the outcome of the tests.
Is such a thing simple or am I going to have to implement a whole new test runner for such a thing?
This attribute is to identify methods that are called once prior to executing any of the tests in a fixture.
Inheritance. The SetUp attribute is inherited from any base class. Therefore, if a base class has defined a SetUp method, that method will be called before each test method in the derived class.
Action Attributes allow the user to create custom attributes to encapsulate specific actions for use before or after any test is run.
The nunit.exe program is a graphical runner. It shows the tests in an explorer-like browser window and provides a visual indication of the success or failure of the tests.
Yes,
Use the [SetUpFixture]
attribute on a class and the [SetUp]
and [TearDown]
attributes on methods with that class.
The SetUp method in a SetUpFixture is executed once before any of the fixtures contained in its namespace. The TearDown method is executed once after all the fixtures have completed execution. In the examples below, the method RunBeforeAnyTests() is called before any tests or setup methods in the NUnit.Tests namespace. The method RunAfterAnyTests() is called after all the tests in the namespace as well as their individual or fixture teardowns have completed exection.
Source (it says 2.4 on the page, but it is available in 2.5)
Take a look at TestFixtureSetUp and TestFixtureTearDown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With