[英]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.