Can we get native C++ code coverage in VS2012 or VS2010 without MSTest?

后端 未结 2 864
日久生厌
日久生厌 2021-01-31 05:46

We would like to measure code coverage for our own automated regression test system run over a fairly large native app. This is a sophisticated, scripted test system using the i

2条回答
  •  悲哀的现实
    2021-01-31 06:12

    Visual Studio 2012's code coverage tool is entirely separate from the test execution system (full disclosure: I wrote it, but the team that inherited it after I left Microsoft removed some fairly useful functionality). It was rewritten from the ground up in VS 2012 to dynamically instrument native (x86 and x86-64) and managed code (.NET and Silverlight) when it loads into the process instead of modifying executables on disk.

    You can find CodeCoverage.exe in "%ProgramFiles%\Microsoft Visual Studio 11.0\Team Tools\Dynamic Code Coverage Tools".

    To collect data:

    CodeCoverage.exe collect /output:foo.coverage foo.exe foos_args
    

    A configuration file (there's a default one in that directory called CodeCoverage.config) can be specified to control collection.

    To analyze the coverage data, you can open foo.coverage in Visual Studio 2012 or use the coverage tool itself to do the analysis:

    CodeCoverage.exe analyze /output:results.xml foo.coverage
    

    Note: for instrumentation to take place, .pdb files must be discovered for your modules. Since you are building with 2010, they may not work with 2012's DIA so you may have to rebuild with 2012's toolset. If you are not seeing the modules you expect in the coverage analysis, pass /include_skipped_modules to the analyze command; there will be a "reason" attribute telling you why the module was skipped (excluded, no debug information, etc.).

    Edit: Also, unlike previous versions of Visual Studio, 2012's coverage file format is completely self-contained. The modules and .pdbs don't need to be present at analysis time.

提交回复
热议问题