简体   繁体   中英

How to the see output from unit-tests in the Test-Result window in VS2010?

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?

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));
}

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM