如何在 NUnit 3 的 Visual Studio 适配器中启用跟踪输出?

How can I enable trace output in NUnit 3's Visual Studio adapter?

考虑:

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

当 运行 它来自 Visual Studio 2015 时,输出 window(测试)显示没有跟踪线:

------ 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 上运行良好。我需要以某种方式打开它吗?

我的 app.config 没有覆盖默认值 <system.diagnostics>

根据 this discussion,他们出于技术原因删除了它。

另一种解决方案可能是这样的:

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 Adapter 3.4.1.0: Test execution started Running selected tests in C:\ProjectPath\MyUnitTest.dll NUnit3TestExecutor converted 1 of 1
NUnit test cases Before Test Hello After Test NUnit Adapter 3.4.1.0:
Test execution complete
========== Test execution complete: 1 run(0:00:00,7660762) ==========

结论

您不能再对 NUnit 的输出使用 Trace

选项 1: 您可以使用输出 window 查看跟踪信息

选项 2: 在您的启动中,添加一个 TextWriterTraceListener