Add custom message to unit test result

36,201

Solution 1

Assuming you are using MSTest, you can use

System.Diagnostics.Trace.WriteLine("Hello World");

To output whatever you'd like. It will show up in the full results of the test runner.

Solution 2

The example above did not work for me but the following did:

var result = routeManager.UpdateWalkingOrder(previouspremiseFuncLoc, premiseFuncLoc, out message);

Assert.AreEqual(true, result, message);

Where message is any error i want to display in the Error Message Dialog of my Test Result. In the example above I am returning errors that are captured when executing that function and showing it in my test results which is great help for debugging.

In your case you could just display the running time.

Solution 3

I went the same route, trying to find a way to output a message to Test Results. You can simply store your elapsedtime into a String and just use:

Console.WriteLine(elapsedtime);

Worked for me just fine.

Solution 4

Depending on the length of the message, you may want to use Console.WriteLine. It gets added to the test results, column name Output (StdOut), so you can see it without going into test run details.

I find it useful to output some very general information, such as the number of properties that were tested, or any other proof that the tests were actually run.

If you don't have a status message, what if somebody sabotaged your code and deleted everything from the test method body? They are all passing now, but it does not help at all.

Share:
36,201
Rush Frisby
Author by

Rush Frisby

rushfrisby.com

Updated on April 03, 2020

Comments

  • Rush Frisby
    Rush Frisby about 4 years

    Is there a way I can add a custom message to the result of a test method? I want to put a stopwatch on part of the code to see how long its running. I don't need to test that it's running within a certain time frame, just want to see in the result window what the elapsed time was.

  • Gautam Beri
    Gautam Beri over 12 years
    This did work. But is there is anyway to name the output, lets say to capture the passed test data to record it