2016-03-25 5 views
1

NUnitコンソールランナーで/domain = multipleを実行すると、NullReference例外が発生します。NUnit 3.2.0コンソールランナーSystem.NullReferenceException/domain = multipleの場合

/domain = multipleまたは/ domain = singleを指定しないで動作します。 ReSharper 10.0.2を使用して実行すると、 "Use Separate AppDomain"設定がチェックされた状態で、テストアセンブリが並行して実行され、実行されます。

コンソールランナーを使用して複数のアセンブリからパラレル化されたテストを実行できます。静的資産を並行してロードする必要があるため、複数のAppDomainsでテストを実行する必要があります。

問題を再現するための簡単なユニットテストソリューションを作成しました。 2つのプロジェクトがあります。各このように見える一つのテストクラスを有する:ここ

[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) 

答えて

2

、NUnitの3ので、別のプロセス、(/process=Multipleフラグ)の各アセンブリを実行します/domain=multipleフラグは、/process=InProcessまたは/process=Separateと組み合わせて使用​​する場合にのみ意味があります。これは、テストが複数のAppDomainに存在するためです(異なるプロセスではあります)。これらのフラグのいずれかを追加すると、期待どおりに動作します。

つまり、NUnitはこのような状況ではクラッシュするべきではないので、please report it on GitHub.