在 NUnit Console Runner 中使用/domain=multiple运行时,会发生 NullReference 异常。
在没有 /domain=multiple 或 /domain=single 的情况下运行。使用 ReSharper 10.0.2 测试运行程序运行并选中“使用单独的 AppDomain”设置可以按照我想要的方式运行,并并行运行测试程序集。
我希望能够使用控制台运行器从多个程序集并行运行参数化测试。由于这需要并行加载静态资产,因此测试需要在多个 AppDomain 中运行。
我创建了一个简单的单元测试解决方案来重现该问题。有两个项目。每个都有一个测试类,如下所示:
[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);
}
}
以下是控制台结果:
nunit3-console.exe "UnitTestProject1\bin\Debug\UnitTestProject1.dll" "UnitTestProject2\bin\Debug\UnitTestProject2.dll" /domain=multiple
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: 2.0.50727.5485
Test Files
UnitTestProject1\bin\Debug\UnitTestProject1.dll
UnitTestProject2\bin\Debug\UnitTestProject2.dll
Test Run Summary
Overall result: System.NullReferenceException: Object reference not set to an instance of an object.
at NUnit.Common.ColorConsoleWriter.WriteLabel(String label, Object option, ColorStyle valueStyle)
at NUnit.Common.ColorConsoleWriter.WriteLabelLine(String label, Object option, ColorStyle valueStyle)
at NUnit.ConsoleRunner.ResultReporter.WriteSummaryReport()
at NUnit.ConsoleRunner.ConsoleRunner.RunTests(TestPackage package, TestFilter filter)
at NUnit.ConsoleRunner.Program.Main(String[] args)