C# – How to Console.WriteLine from [TestMethod]

cunit testingvisual studio 2010

I am trying to show some information from a [TestMethod] method.

Usually we use NUnit and a line with Console.WriteLine runs fine and we can see it in 'output' window, but on this project we must to use Testing tools embebed with VS2010 and Console.WriteLine doesn't run because we cannot see anything.

Best Answer

OK, you have to use Assert and all that, but the other answers don't answer the actual question. Maybe you have your reasons (as I have mine, which is how I found this question).

This might help you a little:

It turns out to see a test’s output, you just double-click on the test summary line, and all the output is down at the bottom of that window. You get Console.Out messages and (more importantly) {Trace,Debug}.WriteLine()

If you're using ReSharper, select your test method in the Unit Test Sessions pane, and the output will be in the Output tab:

enter image description here

In my case, I just needed to quickly test some performance. As I already have a unit test project, it was quicker to do it this way than having to create a new Console Application. So instead of just telling people why their question is wrong, I believe we should tell them why their question is wrong, but still try to answer the question.

Sorry for the rant.

Related Topic