Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Have you tried Debug.WriteLine()? – svick Mar 9 '12 at 15:14
Have to say: you don't want to do that. The tests become slow, and someone has to watch that console. – Christian Horsdal Mar 10 '12 at 6:47
Hi @user6847, please mark an answer as the correct one, or edit your question to clarify why the question remains unanswered. – Peter Jun 26 '14 at 8:30

I agree with the previous poster that if you need to verify something you assert it...

However... Your Console.WriteLine() message will show, after your test has completed double click the test result line in the Test Results tab, this will open the results for the individual test which contains a "Standard Console Output" section which has your Console.WriteLine() messages.

share|improve this 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.

share|improve this answer
This is a great response. Care about the community people - from the bottom to the top. – Anonymous Type Feb 26 '15 at 0:27
MAN this is difficult to find! Double-click, scroll down, click the tiny blue "output" link at the bottom. Thank you so much. – CindyH Mar 9 at 16:20

Why do you need to "see anything"?

You should just use asserts to validate the test has worked correctly.

share|improve this answer
Agreed. If you're manually checking output, it isn't an automated test anymore! – Tom G Mar 9 '12 at 15:39
Well, I wasn't the one who gave a -1, but I thought about it, because this answer, while it may be a good point, doesn't actually answer the question. – Eric King Mar 9 '12 at 17:11
It's one thing to answer the question, it's another to provide insight the asker didn't think of. It's the difference between giving someone what they want versus what they need. – Michael Brown Mar 9 '12 at 17:30
There's no reason you can't do both. – Eric King Mar 9 '12 at 17:32
If your code isn't working, the text of an output console can give you insight into why its not working. Asserts only allow you to test for things you have already thought of. – Greg Jun 26 '14 at 1:42

You can set the standard output and input of Console to be a TextWriter / TextReader and perform asserts based on the content of those.

share|improve this answer

protected by gnat May 27 at 20:10

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.