8

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.

hello B
  • 207
  • 1
  • 2
  • 2

4 Answers4

13

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.

Peter
  • 988
10

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.

wessiyad
  • 219
  • 1
  • 7
3

Why do you need to "see anything"?

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

ozz
  • 8,352
2

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

RobB
  • 51