0
votes

I have a test fixture class ABC which inherits from Base Class with name BaseTest. Both BaseTest and ABC has testfixture teardown and testfixture setup defined.

I want to know which TestFixtureSetUp and TestFixtureTearDown gets executed first. Please see the code below:

public class BaseTest 
{
  [TestFixtureSetup]
  public void BaseSetup()
  {
  }

  [TestFixtureTearDown]
  public void BaseTearDown()
  {
  }
}

 public class ABC : BaseTest
{
  [TestFixtureSetup]
  public void Setup()
  {
  }

  [TestFixtureTearDown]
  public void TearDown()
  {
  }
}

What i want to know is whether BaseTearDown gets executed first or TearDown?

1
Why not make the base methods virtual and override them in the derived class instead? Then you have full control.Lasse V. Karlsen

1 Answers

0
votes

The order of execution in this case is strictly defined by NUnit.

Base class TestFixtureSetUp will always execute first, the the derived class TestFixtureSetUp. TestFixtureTearDown methods execute in the reverse order: derived class first followed by bsse class.

Note that TestFixtureSetUp and TestFixtureTearDown are used in earlier releases of NUnit. In more recent versions use OneTimeSetUp and OneTimeTearDown instead. The order of execution remains the same.