Collecting Code Coverage Data from a Load Test

So I was asked an interesting question today at our VSTS/ALM Seminar in Phoenix:  Is code coverage data collected as part of a load test?

Well, yes and no. 

  • No:  Code coverage info is collected as part of running a unit test, not a load test.
  • Yes:  If you run a unit test as part of a load test, code coverage is implicitly collected because the load test is calling that unit test (over and over).

Last element to note:  When viewing code coverage results for a load test run (again, collected when unit tests are included in the test mix for a load test), the data you're viewing is aggregated from all the unit test runs.  This is actually a good thing - I can run a load test that executes a unit test 100,000 times very quickly.  I don't want to look through each run, but rather the cumulative result for code coverage.  This is possible because code coverage is primarily a percentage value.

This aggregate view is based on the unit test, regardless if the unit test is a "static" or data-driven test (a data-driven test can alter the code coverage results between runs, so again, and aggregate view is easiest to interpret).