如何在命令行中使用 MS 代码覆盖工具? [英] How to use MS code coverage tool in command line?

查看:25
本文介绍了如何在命令行中使用 MS 代码覆盖工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 C++ 代码.

I have the following C++ code.

#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 二进制文件.

Then, I instrument the execution and generated the .coverage binary.

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

当我在 VS2010 中打开覆盖文件时,我没有得到任何结果.

When I open the coverage file in VS2010, I got nothing in its results.

可能有什么问题?我按照这篇文章中的说明进行操作.

What might be wrong? I followed the instructions in this post.

推荐答案

你需要在监视器启动后运行你的程序:

You need to run your program after the monitor starts:

  1. <代码>>vsinstr/coverage hello.exe
  2. <代码>>启动 vsperfmon/coverage/output:mytestrun.coverage
  3. <代码>>你好.exe
  4. <代码>>vsperfcmd/shutdown

当您运行第 3 步时,您应该会在 vsperfmon.exe 中看到一些通知,提示 hello.exe 已启动.

When you run step 3, you should see some notification in vsperfmon.exe that hello.exe has started.

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

If you plan on doing multiple test runs, you only need to run steps 2-4. In other words, you only need to instrument your binary (step 1) once after it's built.

这篇关于如何在命令行中使用 MS 代码覆盖工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆