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

时间:2016-08-03 13:08:28

标签: .net visual-studio visual-studio-2015 nunit nunit-3.0

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

从VS 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和VS 2013上运行良好。我是否需要以某种方式启用它?我的app.config没有覆盖默认<system.diagnostics>

2 个答案:

答案 0 :(得分:12)

根据this讨论,由于技术原因,他们将其删除了。

替代解决方案可能是这样的:

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:测试执行已开始运行所选测试   在C:\ ProjectPath \ MyUnitTest.dll中,NUnit3TestExecutor转换为1的1   NUnit测试用例测试之前测试之后Hello NUnit Adapter 3.4.1.0:
  测试执行完成
  ==========测试执行完成:1次运行(0:00:00,7660762)==========

结论

您无法再对NUnit的输出使用Trace

答案 1 :(得分:1)

选项1::您可以使用输出窗口查看跟踪信息 选项2:在启动时添加TextWriterTraceListener