Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I precisely time a test run in visual studio 2010

I have a suite of unit tests for my project which I run using the visual studio test runner. I want to know how long the test run takes when it runs. The test run details screen shows me the start and end times of the run, but only to the nearest second. My test suite at the moment is taking less than a second to complete, so I can't tell if my suite of 50 tests is taking < 0.1 second (good!) or up to 1 second (bad!).

Is there any way to enable this level of precision?

like image 995
saus Avatar asked Oct 19 '11 01:10

saus


People also ask

How do you run a specific test in VS?

Tests can be run from Test Explorer by right-clicking in the code editor on a test and selecting Run test or by using the default Test Explorer shortcuts in Visual Studio.

How can I run unit test faster?

Run your tests in parallel I've already covered this in another blog post “PARALLELISM: NUNIT VS. XUNIT” that running your tests in parallel can significantly improve the speed of your test runs. Basically this means all your tests will run "next to each other" instead of "one by one".

How do I Debug a single unit test in Visual Studio?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.


1 Answers

In your root solution directory, there is a folder called Test Results following the test runs. If you look in there, each run spits out a .TRX file with timestamp of the test run as part of its name. Open this file, and you'll see that it's an XML file with a bunch of hard-to-read information about the test run. If you look for the XML nodes "UnitTestResult", each will have an attribute called "duration". This will tell you how long each individual test took to run (assuming the test was run).

I have a good bit of experience with this as I wrote an open source utility that takes these TRX files, parses them, and generates an HTML report of the results. One of the things that it shows you is test time duration, for individual tests, test classes in aggregate, and the test run as a whole.

Lest this come off as a plug for my tool, I won't post the link unless someone is curious. But, suffice it to say, you can get the test's execution time from the TRX file without debug trace or the console or editing your test code.

Edit: And the precision is ridiculously high. Example entry is 00:00:00.0015890 for a single unit test.

like image 184
Erik Dietrich Avatar answered Sep 21 '22 21:09

Erik Dietrich