Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace Console.WriteLine in NUnit

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.

like image 211
sgtz Avatar asked Jul 26 '11 16:07

sgtz


3 Answers

In NUnit v3, you can also write to the test results output for debugging with

TestContext.Out.WriteLine("Message to write to log");
like image 110
Ashitakalax Avatar answered Oct 17 '22 14:10

Ashitakalax


You can see the console output. You just have to select the "Text Output" tab in the NUnit GUI runner.

Enter image description here

If you are using the ReSharper test runner, the 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:

Enter image description here

You should then get something as follows:

Enter image description here

like image 24
Tim Lloyd Avatar answered Oct 17 '22 14:10

Tim Lloyd


Try using System.Diagnostics.Debug.WriteLine instead.

like image 34
Paul Creasey Avatar answered Oct 17 '22 15:10

Paul Creasey