Reputation: 829
I want to be able to run parameterized tests from multiple assemblies in parallel using the NUnit 3 console runner. The key is that I want to be able to run the static initializers in parallel (the slow part of the tests).
I am able to get this to work using the ReSharper 10 test runner in VisualStudio. When I run the same project in the NUnit 3 console runner, the static initializers do not run in parrallel.
I created a simple unit testing solution to reproduce the issue. There are are two projects. Each project has one test class that looks like the class below. I added logging to show that the tests do not run in parallel from the console runner.
[TestFixture]
public class UnitTest1
{
public static IEnumerable Test1Static
{
get
{
Console.WriteLine($"before sleep 1 - {DateTime.Now}");
Thread.Sleep(12000);
Console.WriteLine($"after sleep 1 - {DateTime.Now}");
return new List<bool> { true, true };
}
}
[Test, TestCaseSource(nameof(Test1Static))]
public void TestMethod1(bool tc)
{
Assert.IsTrue(tc);
}
}
Console runner results:
C:\dev>"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" "C:\Users\username\Documents\Visual Studio 2015\Projects\testn
unit1\UnitTestProject1\bin\Debug\UnitTestProject1.dll" "C:\Users\username\Documents\Visual Studio 2015\Projects\testnunit1\UnitTestProjec
t2\bin\Debug\UnitTestProject2.dll"
NUnit Console Runner 3.2.0
Copyright (C) 2016 Charlie Poole
Runtime Environment
OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
CLR Version: 4.0.30319.42000
Test Files
C:\Users\username\Documents\Visual Studio 2015\Projects\testnunit1\UnitTestProject1\bin\Debug\UnitTestProject1.dll
C:\Users\username\Documents\Visual Studio 2015\Projects\testnunit1\UnitTestProject2\bin\Debug\UnitTestProject2.dll
before sleep 1 - 4/6/2016 3:13:34 PM
after sleep 1 - 4/6/2016 3:13:46 PM
before sleep 2 - 4/6/2016 3:13:47 PM
after sleep 2 - 4/6/2016 3:13:59 PM
Run Settings
WorkDirectory: C:\dev
ImageRuntimeVersion: 4.0.30319
ImageTargetFrameworkName: .NETFramework,Version=v4.5.2
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 8
Test Run Summary
Overall result: Passed
Upvotes: 1
Views: 3726
Reputation: 13736
You haven't told NUnit to run the two assemblies in parallel processes. Add --process:Parallel to your command-line. Suggest reading the version 3 docs at https://github.com/nunit/docs/wiki and not going by the older version documentation.
Depending on the performance, you may want to reduce the number of parallel threads per process (shown as a default of 8 on your machine) to a lower number.
Upvotes: 1