-
Notifications
You must be signed in to change notification settings - Fork 747
Closed
Description
Issue
If I run the following test fixture, the test_that_dispose_was_called
passes because the Dispose
method is called as expected.
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
public class Test_fixture : IDisposable
{
private static bool _disposeWasCalled;
[Test, Order(0)]
public void test_running_first() => Assert.Pass("Some test running before");
[Test, Order(1)]
public void test_that_dispose_was_called() => Assert.That(_disposeWasCalled);
[TearDown]
public static void TearDown(){}
public void Dispose() => _disposeWasCalled = true;
}
However, if I remove the TearDown
method, the Dispose
method is no longer called and _wasDisposed
remains false.
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
public class Test_fixture : IDisposable
{
private static bool _disposeWasCalled;
[Test, Order(0)]
public void test_running_first() => Assert.Pass("Some test running before");
[Test, Order(1)]
public void test_that_dispose_was_called() => Assert.That(_disposeWasCalled);
public void Dispose() => _disposeWasCalled = true;
}
Expected
I would have expected Dispose
to be called after every test if the fixture has the attribute FixtureLifeCycle(LifeCycle.InstancePerTestCase)
set on it, independent of the presence of a TearDown
method. This is expectation is based on the documentation of the FixtureLifeCycleAttribute, which states that IDisposable
fixtures are disposed after each test.