Search code examples
c#testingcontinuous-integrationxunit.net-6.0

.NET 6 run XUnit tests without parallelization


We have issue with our .NET 6 CI running with Drone. We have tests which run against a real postgres database.

Tests run perfectly fine locally because Rider doesn't parallelize them.

But, on the CI, tests randomly fail because the data in the database is not as expected for a given test.

Our understanding (as per the randomness of the failures) is that the tests are run in parallel in the CI.

So far, we tried an XUnit config file (xunit.runne.json) :

{
    "parallelizeAssembly": false,
    "parallelizeTestCollections": false,
    "maxParallelThreads": -1
}

And adding a [Collection] attribute with a name on the parent class of all the test classes :

[Collection("Database Test")]

In the CI, the tests are run using dotnet test.

Any clue about that ? Thank you in advance


Solution

  • For people having similar issues, our problem was that the tests in the CI were using the same database. Hence, when multiple pipeline were running, propblems happened. We fixed the issue by using service container for the databsae in our CI : one temporary database for each CI run.

    The solution which worked to sequentialise the tests inside one given CI run was the [Collection] attribute.