Can I write into the console in a unit test? If yes, why doesn't the console window open?

pencilCake picture pencilCake · Jun 26, 2012 · Viewed 168.3k times · Source

I have a test project in Visual Studio. I use Microsoft.VisualStudio.TestTools.UnitTesting.

I add this line in one of my unit tests:

Console.WriteLine("Some foo was very angry with boo");
Console.ReadLine();

When I run the test, the test passes, but the console window is not opened at all.

Is there a way to make the console window available to be interacted via a unit test?

Answer

Tiago Duarte picture Tiago Duarte · Jul 14, 2016

Someone commented about this apparently new functionality in Visual Studio 2013. I wasn't sure what he meant at first, but now that I do, I think it deserves its own answer.

We can use Console.WriteLine normally and the output is displayed, just not in the Output window, but in a new window after we click "Output" in the test details.

Enter image description here