代码之家  ›  专栏  ›  技术社区  ›  code_fodder

如何让nunit3控制台将调试输出到屏幕(在Windows框上)?

  •  9
  • code_fodder  · 技术社区  · 8 年前

    对于前两个,我可以获得调试输出(Console.Write(…)。在VisualStudio2013中,可以在测试后单击“输出”链接进行查看,在GUI中,调试显示在“输出”窗口中。

    当我用nunit3控制台运行它时。我刚拿到总结报告。我试图查看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");

    1 回复  |  直到 5 年前
        1
  •  27
  •   Peter Mortensen Pieter Jan Bonestroo    5 年前

    你的 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 尽管默认值(没有命令行选项)显示上述输出。