TestFixtureTearDown is not executed after exception in TestFixtureSetUp
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
NUnit Framework |
Triaged
|
Medium
|
Unassigned |
Bug Description
Issue now tracked at https:/
(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 TestFixtureTear
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
{
[TestFixtur
public void TestFixtureSetUp()
{
Console.
}
[SetUp]
public void SetUp()
{
Console.
}
[Test]
public void TestBase()
{
Console.
}
[TearDown]
public void TearDown()
{
Console.
}
[TestFixtur
public void TestFixtureTear
{
Console.
}
}
=======
[TestFixture]
public class Derived : Base
{
[TestFixtur
public new void TestFixtureSetUp()
{
Console.
}
[SetUp]
public new void SetUp()
{
Console.
}
[Test]
public void TestDerived()
{
Console.
}
[TearDown]
public new void TearDown()
{
Console.
}
[TestFixtur
public new void TestFixtureTear
{
Console.
}
}
=======
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.
throw new Exception(
}
=======
Executing TestDerived now gives this output:
=======
Running TestFixtureSetUp Base
Running TestFixtureSetUp Derived
Running SetUp Base
Running TearDown Derived
Running TearDown Base
Test 'Avl.TestAutoma
Base.cs(18,0): at Avl.TestAutomat
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...
=======
[TestFixtur
public void TestFixtureSetUp()
{
Console.
throw new Exception(
}
=======
... then running TestDerived gives the following output:
=======
Running TestFixtureSetUp Base
Test 'Avl.TestAutoma
TestFixture failed: SetUp : System.Exception : Exception in TestFixtureSetUp Base
at Avl.TestAutomat
=======
(See also https:/
Changed in nunitv2: | |
status: | New → Triaged |
importance: | Undecided → Medium |
affects: | nunitv2 → nunit-3.0 |
description: | updated |
tags: | added: github |