Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; MenuItem has a deprecated constructor in /home/charl422/nunitsoftware.com/nunitv2/php/build_menu.php on line 34
NUnit - SetupFixture
NUnit 2.6.6 Legacy Documentation. View NUnit 3 Documentation

SetUpFixtureAttribute (NUnit 2.4)

This is the attribute that marks a class that contains the one-time setup or teardown methods for all the test fixtures under a given namespace. The class may contain a method marked with the OneTimeSetUpAttribute and a method marked with the OneTimeTearDownAttribute.

There are a few restrictions on a class that is used as a setup fixture.

The OneTimeSetUp method in a SetUpFixture is executed once before any of the fixtures contained in its namespace. The OneTimeTearDown 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.

Only one SetUpFixture should be created in a given namespace. A SetUpFixture outside of any namespace provides OneTimeSetUp and OneTimeTearDown for the entire assembly.

Example:

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [SetUpFixture]
  public class MySetUpClass
  {
    [OneTimeSetUp]
	RunBeforeAnyTests()
	{
	  // ...
	}

    [OneTimeTearDown]
	RunAfterAnyTests()
	{
	  // ...
	}
  }
}
Imports System
Imports Nunit.Framework

Namespace Nunit.Tests

  <SetUpFixture()> Public Class MySetUpClass
    <OneTimeSetUp()> Public Sub RunBeforeAnyTests()
	  ' ...
	End Sub
	
	<OneTimeTearDown()> Public Sub RunAfterAnyTests()
	  ' ...
	End Sub
  End Class
End Namespace
#using <Nunit.Framework.dll>
using namespace System;
using namespace NUnit::Framework;

namespace NUnitTests
{
  [SetUpFixture]
  public __gc class MySetUpClass
  {
    [OneTimeSetUp] public void RunBeforeAnyTests();
	[OneTimeTearDown] public void RunAfterAnyTests();
  };
}

#include "cppsample.h"

namespace NUnitTests {
  // ...
}
package NUnit.Tests;

import System.*;
import NUnit.Framework.SetUpFixture;


/** @attribute NUnit.Framework.SetUpFixture() */
public class MySetUpClass
{
  /** @attribute NUnit.Framework.OneTimeSetUp() */
  public void RunBeforeAnyTests()
  { /* ... */ }

  /** @attribute NUnit.Framework.OneTimeTearDown() */
  public void RunAfterAnyTests()
  { /* ... */ }
}

See also...