OneTimeSetUpAttribute (NUnit 2.6.5)
This attribute is used inside a TestFixture to decorate a method that is executed once prior to executing any of the tests in the fixture. It is also used inside a SetUpFixture to decorate a method that is executed once prior to executing any of the tests in a particular namespace or assembly.
OneTimeSetUp methods may be either static or instance methods. If you define more than one OneTimeSetUp method in the same class, the order of execution is unspecified. Normally, you should not do this.
OneTimeSetUp methods in a base class are executed prior to those in a derived class.
If a OneTimeSetUp method fails or throws an exception, none of the subordinate tests are executed and a failure or error is reported.
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() { /* ... */ } }