Printing to the console with NUnit Engine

718 views Asked by At

How can I print to the NUnit console when using NUnit engine? I have already tried using Console.Write, TestContext.Write, and System.Diagnostics.Debug.WriteLine but none of them will output anything to the console; as of right now, the NUnit console has no output at all. I need a solution where I can print to the console in both the project when NUnit engine is running as well as in the tests themselves. What would be the correct way to do this?

1

There are 1 answers

12
Charlie On

Since you are running NUnit tests from a program, by calling the engine, no output is produced. If you think about it, programs that use a library don't normally want that library to produce output without being told to do so.

In this case, all output from your tests are sent back to you in the form of events. All normal writes (Console.Write, TestContext.Write) come to you bundled in the test result. Immediate writes (Console.Error, TestContext.Error, TestContext.Progress) come in the form of testoutput events. It's up to you to do what you want with them.

Both the NUnit console runner and the gui have to do this, so you can check the code for some ideas about how to handle the events.