As you know, NUnit 2.5 changed the semantics of SetUp/TearDown attributes. Now it's no longer necessary to declare them virtual in base test classes: NUnit detects and properly chain SetUp/TearDown calls.
But in case these methods are declared as virtual, bad things may happen if test classes are decorated with Isolated attritbute.
Let's start with example that works (no Isolated attribute). Here's the code:
[TestFixture]
public class TestBase
{
[SetUp]
public virtual void SetUp()
{
Console.WriteLine("TestBase.SetUp");
}
}
[TestFixture]
public class TestClass : TestBase
{
[SetUp]
public override void SetUp()
{
base.SetUp();
Console.WriteLine("TestClass.SetUp");
}
[Test]
public void Test()
{
Console.WriteLine("TestClass.Test");
}
}
Here's the output:
TestBase.SetUp
TestClass.SetUp
TestClass.Test
Now we add Isolated attribute to the base class. And the output changes:
TestBase.SetUp
TestClass.SetUp
TestClass.SetUp
TestClass.Test
You see, TestClass.SetUp is called twice which is wrong. But the worst happens if both base and derived classes are decorated with Isolated attribute: the test causes stack overflow! TestClass.SetUp is called endlessly.
There is a workaround to this: don't declare SetUp/TearDown attributes as virtual/override and don't call base.SetUp from an override, just let NUnit 2.5 will chain the calls. But since this is a new feature in NUnit, there are thousands tests that are written using virtual SetUp/TearDown methods, and they will not run properly. Ours don't.