你的
Console.WriteLine(...)
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
之前
另一个输出,即使它是测试中的最后一个输出。
你也不需要
--trace
命令行选项。这是用于NUnit内部跟踪。控制输出的命令行选项是
--labels
尽管默认值(没有命令行选项)显示上述输出。