I am testing a ASP.NET application and would like to get code coverage information about how much of the product code my integration tests exercise. Our libraries are already instrumented and the symbols (pdb) files are available, but I need to know exactly how to enable Visual Studio to capture the code executing within IIS and return the .coverage file. My integration tests are a mix of web api tests and Selenium browser tests.
Can this be done?
On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.
Going back to code coverage, code coverage is nothing more but checking which lines of code were executed during a test run. A single integration test might be hitting a great amount of lines of code, giving a big boost of code coverage.
Live Unit Testing automatically runs any impacted unit tests in the background and shows your code coverage live in Visual Studio. As you modify your code, Live Unit Testing lets you know if your code changes are covered by existing tests or if you need to write new tests.
Yes, you can do this using the Dynamic Code Coverage tools that ship with Visual Studio 2013. I'm using Premium, so I can't say for sure which versions may or may not have this component.
The command to start coverage and hook it into IIS is as follows:
<VisualStudioInstallDirectory>\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe collect /IIS /session:WebSession /output:<CoverageOutputFileName>.coverage
This will restart IIS and start up the coverage process.
Run your integration tests (or do manual testing if you want). When finished, stop the coverage tool with the following command:
<VisualStudioInstallDirectory>\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe shutdown /session:WebSession
This will complete creating the coverage file which can then be opened in Visual Studio. Note, that the shutdown command leaves the CodeCoverage.exe running. Restarting IIS will shut down CodeCoverage.exe processes.
A few other notes:
If you want to convert your coverage file to xml so that it can be consumed by other tools (such as ReportGenerator), you can use the following command to convert the coverage file:
\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe analyze InputCoverageFile.coverage /output:OutputFile.coveragexml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With