Skip to content

Dispose is not called on test fixtures with LifeCycle.InstancePerTestCase without TearDown method #3953

@Crown0815

Description

@Crown0815

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;
}

image

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;
}

image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions