chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
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.
asked by vagif (19.4k points)

2 Answers

0 votes
Hi Vagif,

I checked it out and indeed it's a bug.
Thank you for reporting it, we'll update you once it's fixed.
answered by ohad (35.4k points)
0 votes
Hi Ohad,

Just to let you know that the bug is still there, I just checked the latest version, 5.4.3. :(
answered by vagif (19.4k points)
...