NUnit
|    
* *
    |

These attributes are used to construct the test environment prior to running the tests (TestFixtureSetUp and SetUp) and also to restore the environment after the tests are completed (TestFixtureTearDown and TearDown)

TestFixtureSetUp/TestFixtureTearDown (NUnit 2.1)
These two attributes are used inside a TestFixture to provide a single set of functions that are performed once (TestFixtureSetUp) prior to executing any of the tests in the fixture and once after (TestFixtureTearDown) all tests are completed. A TestFixture can have only one TestFixtureSetUp method and only one TestFixtureTearDown method. If more than one of each type is defined the TestFixture will not be run. It will compile however.

Example:

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

  [TestFixture]
  public class SuccessTests
  {
    [TestFixtureSetUp] public void Init()
    { /* ... */ }

    [TestFixtureTearDown] public void Dispose()
    { /* ... */ }

    [Test] public void Add()
    { /* ... */ }
  }
}

SetUp/TearDown (NUnit 2.0)
These two attributes are used inside a TestFixture to provide a common set of functions that are performed prior (SetUp) and after (TearDown) a test method is called. A TestFixture can have only one SetUp method and only one TearDown method. If more than one of each type is defined the TestFixture will not be run. It will compile however.

Example:

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

  [TestFixture]
  public class SuccessTests
  {
    [SetUp] public void Init()
    { /* ... */ }

    [TearDown] public void Dispose()
    { /* ... */ }

    [Test] public void Add()
    { /* ... */ }
  }
}


SetUp/TearDown Inheritance
These two attributes are inherited from base classes. Therefore, if a base class has defined a SetUp method that method will be called prior to execution of test methods in the derived class. If you wish to add more SetUp/TearDown functionality in a derived class you need to mark the method with the appropriate attribute and then call the base classes method.
 



Copyright © 2002-2004 James W. Newkirk, Alexei A. Vorontsov. All Rights Reserved.
|