2013-12-21 96 views
0

我想利用Visual Studio代码覆盖能力将Visual Studio作为对环境的诊断测试,而无需Visual Studio实例。使用Visual Studio代码覆盖作为外部工具

我无法获得关于如何完成的教程或指南。 那么如何做到呢? 即使是指导方针也不错。

+0

哪个Visual Studio版本? – jessehouwing

+0

目前使用2012年,不久将移至2013年。 –

回答

1

在Visual Studio 2012或更新版本中,您可以使用vstest.console.exe来调用测试来收集代码覆盖率。 /enableCodeCoverage commandline switch启用它。

您也可以使用旧的vsperfcmd工具从命令行收集覆盖范围。这要求您至少在计算机上安装Visual Studio Test Agent。这不是完整的Visual Studio安装,但它包含运行测试和收集覆盖范围详细信息所需的组件。

How to setup the VsPerfCmd tool can be found here in this MSDN post。我复制的步骤:

我假设你想在MyApp.exe的

  1. 打开Visual Studio命令代码覆盖率提示

  2. 添加%ProgramFiles%\Microsoft Visual Studio 10\Team Tools\Performance Tools的路径

    set path=%path%;'%ProgramFiles%\Microsoft Visual Studio 10\Team Tools\Performance Tools'

  3. CD到包含MyApp.exe的文件夹

  4. 仪器MyApp.exe中的覆盖面:

    vsinstr -coverage MyApp.exe

  5. 启动覆盖监视器来收集代码覆盖率数据:

    vsperfcmd -start:coverage -output:MyApp.coverage

  6. 运行仪表MyApp.exe的:

    MyApp.exe

  7. 关闭显示器一旦MyApp.exe的完成:

    vsperfcmd -shutdown

  8. 打开在Visual Studio

的MyApp.coverage文件随着Test Agent installed on the machine, you can also trigger a test run from Visual Studio(即使已安装在不同的机器上)。