C# – How to unit test console output

There’s two ways to unit test code that writes to the console (Console.WriteLine() / Console.Write()): In this article, I’ll show how to do both options. Option 1 – Capture the output with Console.SetOut() Let’s say you want to unit test the following code that outputs to the console with Console.WriteLine(): You can unit test this … Read more

C# – Unit test an event handler

An event handler is a method that is registered to listen to an event. When the event is invoked, the event handler method is called. You may be tempted to directly call the event handler to unit test it. It’s better to actually raise the event though, and then check the side effects of the … Read more