Replace Console.WriteLine in NUnit

Viewed 57610

I haven't done much with NUnit before, but I just wanted to dump some text to a window in a console type fashion. For example:

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.

5 Answers

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.

Use the Test-Output view.

Steps:

  1. Open Test Explorer
  2. Select any particular test
  3. Run it if it has never been run.
  4. Click on the output link on the test results pane.

There is no need to replace Console.WriteLine with anything as this view logs messages from:

Console.WriteLine

Trace.WriteLine

Debug.WriteLine

TestExplorer.Out.WriteLine

Enter image description here

Related