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