6

I'm new to unit testing and I want to see output from my tests.

Let's assume I'm testing for the existance of certain objects:

List<MyObject> actual = target.GetMyObjects(); Assert.IsTrue(actual.Count > 0, String.Format("{0} objectes fetched", actual.Count)); 

In the 'Test Result' window in VS2010 I want to see the result of "String.Format("{0} objectes fetched", actual.Count)".
Is that possible?

4 Answers 4

6

Found it:
I added the column Output(StdOut) to the Test Result window.

I changed the end of my test method to this:

bool success = actual.Count > 0; Assert.IsTrue(success, "No models in the database"); if (success) { Console.Write(String.Format("{0} models fetched", actual.Count)); } 
Sign up to request clarification or add additional context in comments.

Comments

2

Yes this is possible. If the test fails whatever message that you put in the second parameter might be useful.In your case if the count value is important for you to debug the error go ahead with it. Even if the failing or succeeding the test is automated later when debugging this information might be helpful. http://www.creatingsoftware.net/2010/03/best-practices-for-assert-statements-in.html

1 Comment

So, how can I see my message in the Test Result window if the test succeded?
0

Alternatively you could use

Debug.Print("whatever"); 

And then when you run your test, you get a hyperlink "Output" in the success/fail window which will show all of your debug messages.

Obviously you need to add

Using System.Diagnostics; 

Dom

Comments

-1

No, you don't want to see the output.

Each unit test must either succeed or fail. This enables the test runner to aggregate the test results into a single Fail/Pass test result. If human inspection is required, the point of unit testing is lost - it must be automated.

3 Comments

Yes I want the test to succeed. I also want this to see this output in the test result window. I've grouped several tests into an ordered test but I partially want feedback from them, like in this case, the test if there are items present. Human inspection is not required, but if I take a look at the test and see the amount of items, that is and information that I'd like to see
You can't get output from assertions, but you can use Console.WriteLine: blogs.msdn.com/b/ploeh/archive/2007/10/06/…
In the long run, you don't want to see the output. But when you're writing tests, sometimes the output can be very useful to understand a test failing for a non-obvious reason.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.