views:

273

answers:

3

There are six tabs in the NUnit Test runner:

Errors and Failures
Tests Not Run
Console.Out
Console.Error
Trace
Log

I know what Errors and Failures are for but the purpose of the remaining tabs is confusing. Both Console.Out and Trace appear to serve a similar purpose.

As a comment has pointed out, I have written a similar question asking how does one write to all of the tabs. In this question, I am asking why does one write to each of the tabs? Why does one write to the Console.Out vs the Trace vs the Log tab? What is the intended purpose of each tab?

A: 

I would expect Console.Out to be used when writing or debugging your tests, whereas Trace would be used to display trace output from the code under test. Trace output in your code can be conditional using Trace.WriteIf etc and turned on by switch definitions in your config file.

marklam
+1  A: 

The Tests Not Run tab displays tests which were skipped. These are tests which have the Ignore() attribute defined. This is useful if you want to temporarily disable a test that is known to be temporarily invalid, or that is too time consuming to run on a regular basis.

The remaining tabs are all covered in your other question:

  • Console.Out -> Console.WriteLine()
  • Console.Error -> Console.Error.WriteLine()
  • Trace -> System.Diagnostics.Trace.WriteLine()
  • Log -> log4net output

Console.Out writes data to stdout.

Console.Error writes data to stderr.

Trace writes data to the Trace Ojbect .

Log4Net writes to a "variety of log targets."

The purpose of all of these is the same: to obtain insight into what your code is doing as it runs, without using breakpoints and a debugger. Which one you use depends on your requirements: The Console methods produce user-visible output. Trace is easy to show/hide (and includes quite a lot of extra information), but doesn't appear to have any kind of persistence backing it. Logging can be permanent, but requires the overhead of maintaining the log file.

AaronSieb
thanks for your response. *Why* would I write to Console.Out vs Trace vs Log?
MedicineMan
Edited to clarify.
AaronSieb
A: 
  • Console.Out = output from your test code (e.g. dump contents of objects returned by methods being tested).

  • Console.Error = output details of errors detected by your test code

  • Trace = diagnostics tracing from the code being tested.

Joe