Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom message to unit test result

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.

like image 393
Rush Frisby Avatar asked Jan 04 '11 01:01

Rush Frisby


People also ask

Do unit tests need comments?

The simple answer is because you have to shoehorn the test into those three steps. So get rid of those comments. They serve no useful purpose and the test is easier to read without them.

How do I create a unit test report in Visual Studio?

To generate unit tests, your types must be public. Open your solution in Visual Studio and then open the class file that has methods you want to test. Right-click on a method and choose Run IntelliTest to generate unit tests for the code in your method. IntelliTest runs your code many times with different inputs.


2 Answers

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.

like image 187
vcsjones Avatar answered Sep 27 '22 19:09

vcsjones


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.

like image 30
Adrian Hedley Avatar answered Sep 27 '22 18:09

Adrian Hedley