.net-corexunit

The next xUnit test starts to run before previous cleanup in IClassFixture


Using "xunit": "2.2.0-beta4-build3444" with ASP.NET Core I have two integration tests that interact with the same database table and seed some data using IClassFixture:

// FooTestData inserts two rows in TableA
// In FooTestData.Dispose() the rows are deleted
public class FooTest : IClassFixture<FooTestData>
{
    [Fact]
    public void Test()
    {
        var result = GetAllRowsFromTableA()
        // Assert that result.Count == 2
    }

}

// BarTestData inserts one row in TableA
// In BarTestData.Dispose() the row is deleted
public class BarTest: IClassFixture<BarTestData>
{
    [Fact]
    public void Test()
    {
        // Do something
    }
}

FooTest.Test fails because it starts before BarTestData.Dispose() is called. The amount of rows in the database is 3 if I run all tests at once (not in parallell). How do I fix that ?

UPDATE It seems like the tests are run in parallell even if I tell them not to (Not selecting "Run in parallell" in Visual Studio)


Solution

  • https://xunit.github.io/docs/running-tests-in-parallel.html

    By default xunit > 2.0 runs two tests in paralell regardless of what I tell Visual Studio to do.