Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"dotnet test": how to run xunit tests projects in parallel?

I am runnning all tests projects from solution level with a single command: dotnet test how can I make all tests projects(assemblies) run in parallel?

In Visual Studio there is a simple button "Run tests in parallel" which works perfectly but I need to use dotnet core test command for CI.

like image 857
Deivydas Voroneckis Avatar asked Dec 28 '18 08:12

Deivydas Voroneckis


People also ask

Do xUnit tests run in parallel?

XUnit by default run all test tests in parallel which are sitting in separate class files. This makes it easy to run our test in parallel without us doing any special configuration.

Does dotnet test run tests in parallel?

Luckily, dotnet test using xUnit V2 runs the tests inside of a project (or even inside a solution) in parallel by default. So at least the tests inside of a project will be started in parallel.

How do I run parallel test cases in Visual Studio?

Visual Studio 2019 runs unit tests sequentially when it is suppose to run them in parallel. Click on the Run Tests in Parallel button in Test Explorer. Make sure the icon is highlighted. Run unit tests.


1 Answers

There is currently no supported way to pass flags to dotnet test. You must use configuration files instead.

xunit.runner.json:

{
    "parallelizeAssembly": true
}

parallelizeAssembly defaults to false

Set this to true if this assembly is willing to participate in parallelization with other assemblies. Test runners can use this information to automatically enable parallelization across assemblies if all the assemblies agree to it.

parallelizeTestCollections defaults to true

Set this to true if the assembly is willing to run tests inside this assembly in parallel against each other. Tests in the same test collection will be run sequentially against each other, but tests in different test collections will be run in parallel against each other. Set this to false to disable all parallelization within this test assembly.

like image 87
rickvdbosch Avatar answered Sep 19 '22 17:09

rickvdbosch