Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ToolsDynamic Code Coverage ToolsCodeCoverage.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 ToolsDynamic Code Coverage ToolsCodeCoverage.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 code coverage 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, you need to launch Visual Studio as Administrator to get it to start correctly.
  • 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 ToolsDynamic Code Coverage ToolsCodeCoverage.exe analyze InputCoverageFile.coverage /output:OutputFile.coveragexml


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...