← Back to team overview

nunit-core team mailing list archive

[Bug 1233141] Re: TestFixtureTearDown is not executed after exception in TestFixtureSetUp

 

** Project changed: nunitv2 => nunit-3.0

-- 
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/1233141

Title:
  TestFixtureTearDown is not executed after exception in
  TestFixtureSetUp

Status in NUnit Test Framework:
  Triaged

Bug description:
  (NUnit 2.5.10.11092 wit GUI runner)

  The behaviour of TearDown and TestFixtureTearDown in case of an
  Exception in the corresponding SetUp is described in the same way, but
  behaves differently.

  Decription of TearDown:
  So long as any SetUp method runs without error, the TearDown method is guaranteed to run. It will not run if a SetUp method fails or throws an exception.

  Description of TestFixtureTearDown:
  So long as any TestFixtureSetUp method runs without error, the TestFixtureTearDown method is guaranteed to run. It will not run if a TestFixtureSetUp method fails or throws an exception.

  I have the following two very simple classes:

  ==============================================================
    [TestFixture]
    public class Base
    {
      [TestFixtureSetUp]
      public void TestFixtureSetUp()
      {
        Console.WriteLine("Running TestFixtureSetUp Base");
      }
      [SetUp]
      public void SetUp()
      {
        Console.WriteLine("Running SetUp Base");
      }
      [Test]
      public void TestBase()
      {
        Console.WriteLine("Running Test Base");
      }
      [TearDown]
      public void TearDown()
      {
        Console.WriteLine("Running TearDown Base");
      }
      [TestFixtureTearDown]
      public void TestFixtureTearDown()
      {
        Console.WriteLine("Running TestFixtureTearDown Base");
      }
    }
  ==============================================================
    [TestFixture]
    public class Derived : Base
    {
      [TestFixtureSetUp]
      public new void TestFixtureSetUp()
      {
        Console.WriteLine("Running TestFixtureSetUp Derived");
      }
      [SetUp]
      public new void SetUp()
      {
        Console.WriteLine("Running SetUp Derived");
      }
      [Test]
      public void TestDerived()
      {
        Console.WriteLine("Running Test Derived");
      }
      [TearDown]
      public new void TearDown()
      {
        Console.WriteLine("Running TearDown Derived");
      }
      [TestFixtureTearDown]
      public new void TestFixtureTearDown()
      {
        Console.WriteLine("Running TestFixtureTearDown Derived");
      }
    }
  ==============================================================

  Executing TestDerived works as expected:
  ==============================================================
  Running TestFixtureSetUp Base
  Running TestFixtureSetUp Derived
  Running SetUp Base
  Running SetUp Derived
  Running Test Derived
  Running TearDown Derived
  Running TearDown Base
  Running TestFixtureTearDown Derived
  Running TestFixtureTearDown Base
  ==============================================================

  Now I introduce an Exception in SetUp of Base:
  ==============================================================
      [SetUp]
      public void SetUp()
      {
        Console.WriteLine("Running SetUp Base");
        throw new Exception("Exception in SetUp Base");
      }
  ==============================================================

  Executing TestDerived now gives this output:
  ==============================================================
  Running TestFixtureSetUp Base
  Running TestFixtureSetUp Derived
  Running SetUp Base
  Running TearDown Derived
  Running TearDown Base
  Test 'Avl.TestAutomationFramework.Infrastructure.UnitTests.TestDriver.Derived.TestDerived' failed: SetUp : System.Exception : Exception in SetUp Base
      Base.cs(18,0): at Avl.TestAutomationFramework.Infrastructure.UnitTests.TestDriver.Base.SetUp()

  Running TestFixtureTearDown Derived
  Running TestFixtureTearDown Base
  ==============================================================

  Since the behaviour of TearDown and TestFixtureTearDown in case of an
  exception in the corresponding SetUp function is described the same
  way, word by word, I would expect that if there was an Exception in
  TestFixtureSetUp Base, then also both TestFixtureTearDown Derived and
  TestFixtureTearDown Base will be called.

  However, if I remove the Exception from SetUp Base again and instead add one to TestFixtureSetUp Base...
  ==============================================================
      [TestFixtureSetUp]
      public void TestFixtureSetUp()
      {
        Console.WriteLine("Running TestFixtureSetUp Base");
        throw new Exception("Exception in TestFixtureSetUp Base");
      }
  ==============================================================

  ... then running  TestDerived gives the following output:
  ==============================================================
  Running TestFixtureSetUp Base
  Test 'Avl.TestAutomationFramework.Infrastructure.UnitTests.TestDriver.Derived.TestDerived' failed: TestFixtureSetUp failed in Derived

  TestFixture failed: SetUp : System.Exception : Exception in TestFixtureSetUp Base
     at Avl.TestAutomationFramework.Infrastructure.UnitTests.TestDriver.Base.TestFixtureSetUp() in D:\git\TestAutomationFramework_V2013\Projects\Infrastructure\UnitTests\TestDriver\Base.cs:line 13
  ==============================================================

  (See also https://groups.google.com/forum/#!topic/nunit-
  discuss/6KY1yeJNh5U )

To manage notifications about this bug go to:
https://bugs.launchpad.net/nunit-3.0/+bug/1233141/+subscriptions


References