繁体   English   中英

如何让 nunit3-console 将我的调试输出到屏幕(在 Windows 机器上)?

[英]How do I get nunit3-console to output my debug to screen (on a Windows box)?

我已经使用 NUnit 在 Visual Studio 2013 中成功运行我的 C# 单元测试,使用 NUnit GUI 和 NUnit 控制台。

对于前两个,我可以访问我的调试输出(Console.Write(...))。 在 Visual Studio 2013 中,可以通过在测试后单击“输出”链接进行查看,并且在 GUI 中,调试显示在“输出”窗口中。

当我使用 nunit3-console.exe 运行它时,我只会得到摘要报告。 我试图查看 XML 输出(在 TestResults.xml 中)中的内容,但这只是包含更多相同的摘要报告。

我怎样才能让我的调试也出现在屏幕上?

我的命令行如下所示:

nunit3-console.exe "c:\path\to\my\assebly.dll" --trace=Verbose --test=Regression.Tests.HelloWorld

测试 HelloWorld 有一行Console.Write("Hello World\\r\\n"); 在其中,我想看到它出现在屏幕上(标准输出)。

您的Console.WriteLine(...)应该出现在输出中,但在 NUnit 3 中,您应该在测试中使用TestContext.WriteLine(...) 因为 NUnit 3 能够并行运行您的测试,所以它会捕获该输出,然后在测试完成运行时将其打印到控制台。 这样,输出与测试匹配,而不与其他测试交错。

如果您希望输出在写入时立即消失,请使用TestContext.Progress.WriteLine(...) 例如下面的测试,

    [Test]
    public void ExampleOfConsoleOutput()
    {
        Console.WriteLine("Console.WriteLine In ExampleOfConsoleOutput");
        TestContext.WriteLine("TestContext.WriteLine In ExampleOfConsoleOutput");
        TestContext.Progress.WriteLine("TestContext.Progress.WriteLine In ExampleOfConsoleOutput");
    }

输出以下内容,

=> nunit.v3.TestNameInSetup.ExampleOfConsoleOutput
TestContext.Progress.WriteLine In ExampleOfConsoleOutput
Console.WriteLine In ExampleOfConsoleOutput
TestContext.WriteLine In ExampleOfConsoleOutput

请注意,Progress 消息在其他输出之前输出,即使它是测试中的最后一个。

您也不需要--trace命令行选项。 那是用于 NUnit 内部跟踪。 控制输出的命令行选项是--labels尽管默认值(无命令行选项)显示上述输出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM