I'm new to unit testing and I开发者_JS百科 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.
精彩评论