question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet test running assemblies in parallel (when mixing core and framework test assemblies)

See original GitHub issue

I have an issue where “dotnet test” is running assemblies in parallel. I have tried adding [NonParallelizable] and [assembly: LevelOfParallelism(1)] and also running with the dotnet test CLI option -p:ParallelizeTestCollections=false none of which has helped.

I have:

Solution \ MyLibrary.csproj (netstandard2.0) \ Tests461 (net461) \ TestsCore2 (netcoreapp2.2)

The nuget dependencies of both test csproj files are:

<ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
    <PackageReference Include="NUnit" Version="3.12.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
    <PackageReference Include="NunitXml.TestLogger" Version="2.1.41" />
  </ItemGroup>

When I run the tests using

dotnet test

I get the following logged:

Core SetUp 688503812
Core Enter Test 688503812
461 SetUp 688506609
461 Enter Test 688506609
Core Exit Test 688506812
461 Exit Test 688509625

It even looks like dotnet test is firing up 2 instances of the tester process (which don’t respect each other’s parallelization):

PS E:\MyLibrary> dotnet test
Test run for E:\MyLibrary\TestsCore2\bin\Debug\netcoreapp2.2\TestsCore2.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0-preview-20190715-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
Test run for E:\MyLibrary\Tests461\bin\Debug\net461\Tests461.dll(.NETFramework,Version=v4.6.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0-preview-20190715-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 4.0100 Seconds

Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 4.0288 Seconds
PS E:\MyLibrary>

I have built a simple 3 project solution that reproduces the problem if it would help I can provide.

Other things I have tried:

dotnet test -- NUnit.NumberOfTestWorkers=1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
mikehardercommented, Dec 10, 2019

@tznind: See a workaround I posted here: https://github.com/dotnet/cli/issues/11017#issuecomment-564311592. I verified this works in your minimum repro:

$ dotnet test dirs.proj -p:BuildInParallel=false
Test run for D:\Git\DotnetTestParallelExample\Tests461\bin\Debug\net461\Tests461.dll(.NETFramework,Version=v4.6.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.

Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 4.3995 Seconds
Test run for D:\Git\DotnetTestParallelExample\TestsCore2\bin\Debug\netcoreapp2.2\TestsCore2.dll(.NETCoreApp,Version=v2.2)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.

Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 4.7372 Seconds
 
$ type C:\temp\output.txt
461 SetUp -1944219765
461 Enter Test -1944219750
461 Exit Test -1944216750
Core SetUp -1944214390
Core Enter Test -1944214375
Core Exit Test -1944211375
1reaction
smchan514commented, Jan 29, 2022

For anyone still looking for a solution, there is the command line option -m:1 which specifies the maximum number of concurrent processes to use when building.

dotnet test -m:1 MyUnitTests.sln

Ref:

  1. https://github.com/dotnet/sdk/issues/10178
  2. MSBuild command-line reference – Switches
Read more comments on GitHub >

github_iconTop Results From Across the Web

Run VSTest tests in parallel - Azure Pipelines
Typically, tests in an assembly are run in parallel. These test frameworks interface with the Visual Studio Test platform using a test ......
Read more >
"dotnet test": how to run xunit tests projects in parallel?
Set this to true if the assembly is willing to run tests inside this assembly in parallel against each other. Tests in the...
Read more >
Controlling the Serial and Parallel Test on XUnit
My Project requires both Serial and Parallel test execution on a project. I'd like to know how to handle this situation. A collection...
Read more >
Visual Studio 2019 runs unit tests sequentially when it is ...
Steps to Reproduce. Click on the Run Tests in Parallel button in Test Explorer. Make sure the icon is highlighted. Run unit tests....
Read more >
Running Tests in Parallel
Tests written in xUnit.net version 1 cannot be run in parallel against each other in the same assembly, though multiple test assemblies linked...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found