2011-02-09 102 views
4

我有以下C++代码。如何在命令行中使用MS代码覆盖工具?

#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中打开coverage文件时,结果中什么都没有。

enter image description here

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

回答

8

你需要在你的程序中的显示器启动后:

  1. > vsinstr /coverage hello.exe
  2. > start vsperfmon /coverage /output:mytestrun.coverage
  3. > hello.exe
  4. > vsperfcmd /shutdown

当您运行步骤3中,你应该看到一些在vsperfmon.exe中通知​​hello.exe已启动。

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

+0

Zam。为什么MS不能很容易地记录它? https://msdn.microsoft.com/en-us/library/dd299398(v=vs.90).aspx – granadaCoder 2016-04-28 19:44:03