Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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 at 8:30

4 Answers 4

Why do you need to "see anything"?

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

share|improve this answer
1  
Agreed. If you're manually checking output, it isn't an automated test anymore! –  Tom G Mar 9 '12 at 15:39
    
A minus, and no comment, brilliant –  Ozz Mar 9 '12 at 16:36
3  
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
2  
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. –  Mike Brown Mar 9 '12 at 17:30
2  
There's no reason you can't do both. –  Eric King Mar 9 '12 at 17:32

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

http://msdn.microsoft.com/en-us/library/system.console.setout.aspx

share|improve this answer

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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