Dot-Net

如何在 NUnit 3 的 Visual Studio 適配器中啟用跟踪輸出?

  • August 3, 2016

考慮:

[Test]
public void Test1()
{
   Trace.TraceInformation("Hello");
}

從 Visual Studio 2015 執行它時,輸出視窗(測試)不顯示任何跟踪線:

------ Discover test started ------
NUnit Adapter 3.4.0.0: Test discovery starting
NUnit Adapter 3.4.0.0: Test discovery complete
========== Discover test finished: 9 found (0:00:01.325888) ==========
------ Run test started ------
NUnit Adapter 3.4.0.0: Test execution started
Running selected tests in C:\Projects\bla-bla.dll
NUnit3TestExecutor converted 9 of 9 NUnit test cases
NUnit Adapter 3.4.0.0: Test execution complete
========== Run test finished: 1 run (0:00:03.5445181) ==========

我記得它在 NUnit 2 和 Visual Studio 2013 上執行良好。我需要以某種方式打開它嗎?

Myapp.config沒有覆蓋 default <system.diagnostics>

根據這個討論,由於技術原因,他們將其刪除。

另一種解決方案可能是這樣的:

using NUnit.Framework;

   namespace MyUnitTest {
       [TestFixture]
       public class UnitTest1 {
           [Test()]
           public void Test1() {
               var x = "Before Test";
               TestContext.Progress.WriteLine(x);
               x = "Hello";
               TestContext.Progress.WriteLine(x);
               Assert.IsTrue(x == "Hello");
               x = "After Test";
               TestContext.Progress.WriteLine(x);
           }
       }
   }

根據給定的結果:

NUnit 適配器 3.4.1.0:測試執行開始 在 C:\ProjectPath\MyUnitTest.dll 中執行選定的測試 NUnit3TestExecutor 轉換了 1 個

NUnit 測試案例中的 1 個 測試前你好 測試後 NUnit 適配器 3.4.1.0:

測試執行完成

======= === 測試執行完成:1 次執行(0:00:00,7660762)==========

結論

你不能Trace再在 NUnit 的輸出上使用了。

引用自:https://stackoverflow.com/questions/38744600