Today I though it would be nice to see what my code was logging during my unit tests, and I didn't want to dig through a log file to find the log from one specific test. Since the unit test runner is a different executing assembly than my web project, it can have it's own configuration for logging separate from the application. Knowing this, I should be able to set up this new logging behavior for my tests without changing anything in my main project's configuration.
So what makes it possible to log messages from Common.Logging to the standard unit test output?
- Anything written to Console.Out during a unit test will get captured in the unit test Output.
- Common.Logging ships with a built-in Console.Out logger adapter that we can use without requiring a larger logging framework.
- The code being tested should be doing its logging through the Common.Logging log methods.
- Using NuGet, install the Common.Logging package into your unit test project
- In the unit test project's App.Config file, add the necessary XML to configure the console logger (See XML snippet below)
- Run your unit test(s)
- See the log messages captured during each test in your test output:
And of course, let's not forget the code and configuration details:
Great, I was looking for this functionality. Quick question can we save the DEBUG info in a file too.ReplyDelete