简体   繁体   English

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

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

I have used NUnit to run my C# unit tests successfully within Visual Studio 2013, with the NUnit GUI and with NUnit console.我已经使用 NUnit 在 Visual Studio 2013 中成功运行我的 C# 单元测试,使用 NUnit GUI 和 NUnit 控制台。

For the first two I can get to my debug output (Console.Write(...)).对于前两个,我可以访问我的调试输出(Console.Write(...))。 In Visual Studio 2013, it is viewable by clicking the "output" link after the test and in the GUI the debug is displayed in the "Output" window.在 Visual Studio 2013 中,可以通过在测试后单击“输出”链接进行查看,并且在 GUI 中,调试显示在“输出”窗口中。

When I run this with nunit3-console.exe I just get the summary report.当我使用 nunit3-console.exe 运行它时,我只会得到摘要报告。 I tried to look at what is in the XML output (in TestResults.xml), but that just contains more of the same summary report.我试图查看 XML 输出(在 TestResults.xml 中)中的内容,但这只是包含更多相同的摘要报告。

How can I get my debug to also come out on the screen?我怎样才能让我的调试也出现在屏幕上?

My command line looks like this:我的命令行如下所示:

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

The test HelloWorld has the line Console.Write("Hello World\\r\\n");测试 HelloWorld 有一行Console.Write("Hello World\\r\\n"); in it, and I want to see this appear on the screen (standard output).在其中,我想看到它出现在屏幕上(标准输出)。

Your Console.WriteLine(...) should appear in the output, but in NUnit 3, you should use TestContext.WriteLine(...) in your tests.您的Console.WriteLine(...)应该出现在输出中,但在 NUnit 3 中,您应该在测试中使用TestContext.WriteLine(...) Because NUnit 3 is capable of running your tests in parallel, it captures that output and then prints it to the console when the test finishes running.因为 NUnit 3 能够并行运行您的测试,所以它会捕获该输出,然后在测试完成运行时将其打印到控制台。 That way, the output is matched with the test, not interleaved with other tests.这样,输出与测试匹配,而不与其他测试交错。

If you want your output to go out immediately when it is written, use TestContext.Progress.WriteLine(...) .如果您希望输出在写入时立即消失,请使用TestContext.Progress.WriteLine(...) For example, the following test,例如下面的测试,

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

Outputs the following,输出以下内容,

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

Note that the Progress message was output before the other output even though it is last in the test.请注意,Progress 消息在其他输出之前输出,即使它是测试中的最后一个。

You also don't need the --trace command line option.您也不需要--trace命令行选项。 That is for NUnit internal tracing.那是用于 NUnit 内部跟踪。 The command line option to control output is --labels although the defaults (no command line options) show the above output.控制输出的命令行选项是--labels尽管默认值(无命令行选项)显示上述输出。

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

相关问题 nunit3-控制台运行期间发生FileNotFoundException - FileNotFoundException during nunit3-console running 如何在 Windows 上安装 NUnit 3 控制台并运行测试? - How do I install NUnit 3 console on Windows and run tests? 将参数从nunit3-console传递给TestFixture构造函数,而不是传递给TestMethod - Pass parameters from nunit3-console to TestFixture constructor, not to TestMethod nunit3-console 无效:.csproj 文件类型不受支持 - nunit3-console Invalid: .csproj File type is not supported 使用 nunit3-console runner 时查找配置文件时出错 - Error finding configuration file when using nunit3-console runner 如何使nunit-console在程序集的\\ bin \\ Debug \\中而不是\\ bin \\ x86 \\ Debug中显示? - How do I make nunit-console look in \bin\Debug\ rather than \bin\x86\Debug for assemblies? 如何从Visual Studio以调试模式运行NUnit? - How do I run NUnit in debug mode from Visual Studio? 如何使用C#从VBScript控制台获取输出? - How do I get the output from my VBScript Console using C#? 如何让“RedirectStandardOutput”在 NUnit 中工作? - How do I get 'RedirectStandardOutput' to work in NUnit? 如何从命令行从nunit-console运行nunit 2测试? - How do I run nunit 2 tests from nunit-console from the command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM