简体   繁体   English

是否可以使用Visual Studio获得用于集成测试的代码覆盖率数据?

[英]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. 我正在测试ASP.NET应用程序,并希望获得有关集成测试所使用的多少产品代码的代码覆盖率信息。 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. 我们的库已经过检测,并且符号(pdb)文件可用,但是我需要确切地知道如何使Visual Studio捕获IIS中执行的代码并返回.coverage文件。 My integration tests are a mix of web api tests and Selenium browser tests. 我的集成测试是Web api测试和Selenium浏览器测试的混合。

Can this be done? 能做到吗?

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. 是的,您可以使用Visual Studio 2013附带的动态代码覆盖率工具来执行此操作。我使用的是Premium,因此无法确定哪个版本可能包含此组件,也可能不包含此组件。

The command to start coverage and hook it into IIS is as follows: 启动覆盖并将其挂接到IIS的命令如下:

<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. 这将重新启动IIS并启动覆盖过程。

Run your integration tests (or do manual testing if you want). 运行集成测试(或根据需要进行手动测试)。 When finished, stop the coverage tool with the following command: 完成后,使用以下命令停止coverage工具:

<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. 这将完成创建coverage文件的工作,然后可以在Visual Studio中打开该文件。 Note, that the shutdown command leaves the CodeCoverage.exe running. 请注意,关闭命令使CodeCoverage.exe处于运行状态。 Restarting IIS will shut down CodeCoverage.exe processes. 重新启动IIS将关闭CodeCoverage.exe进程。

A few other notes: 其他一些注意事项:

  • If the specified output coverage file already exists, the code coverage monitor will not start. 如果指定的输出coverage文件已经存在,则代码覆盖率监视器将不会启动。 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. 如果将这些命令作为外部工具嵌入到Visual Studio中,则需要以管理员身份启动Visual Studio才能正确启动它。
  • 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: 如果要将覆盖率文件转换为xml,以便其他工具(例如ReportGenerator )可以使用它,则可以使用以下命令来转换覆盖率文件:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM