23

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.

Deivydas Voroneckis
  • 1,973
  • 3
  • 19
  • 40

1 Answers1

29

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.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
rickvdbosch
  • 14,105
  • 2
  • 40
  • 53
  • Thanks, I've been trying this way before but missed "Copy if newer option". Hope it will be the same efficient as "Run in parallel option" in Visual Studio. :) – Deivydas Voroneckis Dec 28 '18 at 11:59
  • 5
    Try with: `dotnet test -- xunit.parallelizeAssembly=true` . Source https://github.com/Microsoft/vstest/issues/631 – dani herrera Mar 14 '19 at 10:12
  • @daniherrera Is there any way I can easily see which tests have been loaded so far? I swear this is not working the way it's documented. I run the tests manually one by one, they pass. I run the tests all at once and they all fail. The tests are not thread-safe, so this makes sense. I'm using xunit theories. – John Zabroski May 01 '19 at 18:48
  • Note, that if you are using fixtures test runner can't run tests in parallel (guess it's a bug), so you have to stick to single thread by setting `"maxParallelThreads": -1` in your `xunit.runner.json` files or via passing corresponding command line command. – Dmitry Pavlov Jun 03 '19 at 16:46
  • 2
    @daniherrera, there is no such a syntax for xunit, and only xunit.runner.json is supported, see [ref from xunit author](https://github.com/xunit/xunit/issues/1169#issuecomment-287521557) – M.Hassan Jul 04 '20 at 10:57