Is it possible to get code coverage data for integration tests using Visual Studio? Is it possible to get code coverage data for integration tests using Visual Studio? selenium selenium

Is it possible to get code coverage data for integration tests using Visual Studio?


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 the specified output coverage file already exists, the codecoverage monitor will not start. Make sure to use unique filenames or delete any existing files before starting.
  • If you embed these commands as External Tools in Visual Studio, youneed to launch Visual Studio as Administrator to get it to startcorrectly.
  • If you want to convert your coverage file to xml so that it can beconsumed by other tools (such as ReportGenerator), you can usethe following command to convert the coverage file:

    \Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe analyze InputCoverageFile.coverage /output:OutputFile.coveragexml