OneTimeTearDownAttribute (NUnit 2.6.5)
This attribute is used inside a TestFixture to decorate a method that is executed once after executing any of the tests in the fixture. It is also used inside a SetUpFixture to decorate a method that is executed once after executing any of the tests in a particular namespace or assembly.
OneTimeTearDown methods may be either static or instance methods. If you define more than one OneTimeTearDown method in the same class, the order of execution is unspecified. Normally, you should not do this.
OneTimeTearDown methods in a base class are executed after those in a derived class.
So long as any OneTimeSetUp method runs without error, the corresponding OneTimeTearDown method is guaranteed to run. It will not run if the OneTimeSetUp method fails or throws an exception.
Example:
namespace NUnit.Tests { using System; using NUnit.Framework; [TestFixture] public class SuccessTests { [OneTimeSetUp] public void Init() { /* ... */ } [OneTimeTearDown] public void Cleanup() { /* ... */ } [Test] public void Add() { /* ... */ } } }
Imports System Imports Nunit.Framework Namespace Nunit.Tests <TestFixture()> Public Class SuccessTests <OneTimeSetUp()> Public Sub Init() ' ... End Sub <OneTimeTearDown()> Public Sub Cleanup() ' ... End Sub <Test()> Public Sub Add() ' ... End Sub End Class End Namespace
#using <Nunit.Framework.dll> using namespace System; using namespace NUnit::Framework; namespace NUnitTests { [TestFixture] public __gc class SuccessTests { [OneTimeSetUp] void Init(); [OneTimeTearDown] void Cleanup(); [Test] void Add(); }; } #include "cppsample.h" namespace NUnitTests { // ... }
package NUnit.Tests; import System.*; import NUnit.Framework.TestFixture; /** @attribute NUnit.Framework.TestFixture() */ public class SuccessTests { /** @attribute NUnit.Framework.OneTimeSetUp() */ public void Init() { /* ... */ } /** @attribute NUnit.Framework.OneTimeTearDown() */ public void Cleanup() { /* ... */ } /** @attribute NUnit.Framework.Test() */ public void Add() { /* ... */ } }