问题
haven't done much with NUnit before, but just wanted to dump some text to a window in a console type fashion.
e.g. Console.WriteLine("... some information...");
that won't work of course because NUnit is driving things.
I'm in the middle of building some unit tests, and want to dump a list of variable values for inspection during debug. It isn't strictly a unit test if I need to do this I admit that, but it would be convenient.
回答1:
You can see Console output, you just have to select the "Text Output" tab in the NUnit GUI runner.
Update
If you are using the ReSharper test runner, Console output should be displayed. Ensure that the test runner output window is displayed by clicking the "Show Output" button in the test runner tool bar:
You should then get something as follows:
回答2:
In NUnite v3, you can also write to the Test results output for debugging with
TestContext.Out.WriteLine("Message to write to log");
回答3:
Try using System.Diagnostics.Debug.WriteLine
instead.
回答4:
In Visual Studio 2017 , in the Test Explorer
window , there is a link Output
in the lower Test
pane . This brings up anything written to the console during that Unit Test .
回答5:
Just wasted half an hour trying to find Test-Output view. Steps:
- Open Test Explorer
- Select any particular test
- Run it if it has never been run.
- Click on the output link on the test results pane.
No need to replace Console.WriteLine
with anything as this view logs messages from:
Console.WriteLine
Trace.WriteLine
Debug.WriteLine
TestExplorer.Out.WriteLine
Hope someone finds this useful.
来源:https://stackoverflow.com/questions/6833558/replace-console-writeline-in-nunit