C# – write into the console in a unit test? If yes, why doesn’t the console window open

cconsole-applicationnetunit testingvisual studio

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?

Best Answer

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