如何在命令行中使用MS代码覆盖工具?

时间:2011-02-09 22:05:05

标签: c++ visual-studio-2010 profiling code-coverage

我有以下C ++代码。

#include <iostream>
using namespace std;

int testfunction(int input)
{
    if (input > 0) {
        return 1;
    }
    else {
        return 0;
    }
}

int main()
{
    testfunction(-1);
    testfunction(1);
}

我编译它以获得执行

cl /Zi hello.cpp -link /Profile

然后,我检测执行并生成.coverage二进制文件。

vsinstr -coverage hello.exe
start vsperfmon -coverage -output:mytestrun.coverage
vsperfcmd -shutdown

当我在VS2010中打开覆盖文件时,我的结果没有任何结果。

enter image description here

可能有什么问题? 我按照this post中的说明操作。

1 个答案:

答案 0 :(得分:12)

您需要在显示器启动后运行程序:

  1. > vsinstr /coverage hello.exe
  2. > start vsperfmon /coverage /output:mytestrun.coverage
  3. > hello.exe
  4. > vsperfcmd /shutdown
  5. 当您运行第3步时,您应该在vsperfmon.exe中看到hello.exe已启动的一些通知。

    如果您计划进行多次测试运行,则只需执行步骤2-4。换句话说,您只需要在构建二进制文件后对其进行一次检测(步骤1)。

相关问题