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

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

考虑:

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

我的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

关于.net - 如何在 NUnit 3 的 Visual Studio 适配器中启用跟踪输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38744600/

相关文章:

c# - 如何获取avicap32.dll中已连接的网络摄像头列表?

c# - session 超时

visual-studio - Visual Studio 2013 隐藏通知按钮

visual-studio - 如何修复损坏的 Visual Studio 项目依赖项?

mysql - 使用 OR 运算符连接两个表

c# - 为什么我不能有对象的类型约束

asp.net - 独立的 ASP.Net Core 应用程序无法在 Mac 上运行

xaml - VS 2015 RC 中 Xaml 缺少 Intellisense

visual-studio-2015 - 如何在TFS中获取整个GIT存储库URL?

c# - MSBuild 无法在 Azure 云服务 csdef 文件中找到目录