现在的位置: 首页 > 综合 > 正文

Using the Code Coverage Tools from the Command Line

2013年06月24日 ⁄ 综合 ⁄ 共 2065字 ⁄ 字号 评论关闭

Visual Studio provides two command line tools that you can use to instrument an artifact, such as a .dll or .exe, and generate code coverage data: vsinstr.exe and vsperfmon.exe. These tools can be found at: n:/Program Files/Microsoft Visual Studio 9.0/Team Tools/Performance Tools/.

Tool Description

Vsinstr.exe

Used to specify the artifact that you want to instrument. The tool can be used on both managed and native .dll files, .exe files, and assemblies. For more information, see VSInstr.

Example:

vsinstr -coverage <myassembly.exe>

Vsperfmon.exe

Used to collect the code coverage data and write the data to an output file. Start vsperfmon.exe, and then run any test suites or otherwise exercise the code that you want code coverage information for. After the instrumented code has been exited, vsperfmon.exe stops collecting data and writes the data to the *.coverage file. For more information, see VSPerfMon.

Example:

start vsperfmon -coverage -output: mytestrun.coverage

Use the following procedures to instrument and generate code coverage information from the command line.

To instrument an .exe, .dll, or other artifact from the command line

  1. From the Command Prompt, navigate to the location of the artifact you intend to instrument.

    For example: /.../My Documents/Visual Studio 2008/Projects/<myproject>/<myproject>/obj/debug/.

  2. If it is necessary, set PATH to /.../Program Files/Microsoft Visual Studio 9.0/Team Tools/Performance Tools/.

  3. Type the following text:

    Vsinstr -coverage <myprojectbinary>
    

    For example: vsinstr -coverage codecoverage.exe

  4. Press RETURN.

  5. Review the output at the command prompt to determine whether the artifact was instrumented successfully.

    Dd299398.note(en-us,VS.90).gifNote:
    You can safely ignore warning VSP2013.

Now that we have instrumented the artifact, we can now capture code coverage data in the file <mytestrun>.coverage.

To collect code coverage data from the command line

  1. From the Command Prompt, type the following text:

    Start vsperfmon -coverage -output:mytestrun.coverage
    
  2. Press RETURN.

    A second Command Prompt window will open.

  3. Exercise the code in the binary, such as by running test suites.

  4. When you have finished exercising the code, type the following text at the command prompt in the original Command Prompt window:

    vsperfcmd –shutdown
    
  5. In Windows Explorer, search for mytestrun.coverage.

  6. Double-click mytestrun.coverage to view the data code coverage data in Visual Studio.

【上篇】
【下篇】

抱歉!评论已关闭.