問(wèn)題描述
我有以下 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);
}
我編譯它以獲得執(zhí)行
cl /Zi hello.cpp -link /Profile
然后,我檢測(cè)執(zhí)行并生成 .coverage 二進(jìn)制文件.
Then, I instrument the execution and generated the .coverage binary.
vsinstr -coverage hello.exe
start vsperfmon -coverage -output:mytestrun.coverage
vsperfcmd -shutdown
當(dāng)我在 VS2010 中打開(kāi)覆蓋文件時(shí),我沒(méi)有得到任何結(jié)果.
When I open the coverage file in VS2010, I got nothing in its results.
可能有什么問(wèn)題?我按照這篇文章中的說(shuō)明進(jìn)行操作.
What might be wrong? I followed the instructions in this post.
推薦答案
你需要在監(jiān)視器啟動(dòng)后運(yùn)行你的程序:
You need to run your program after the monitor starts:
- <代碼>>vsinstr/coverage hello.exe
- <代碼>>啟動(dòng) vsperfmon/coverage/output:mytestrun.coverage
- <代碼>>你好.exe
- <代碼>>vsperfcmd/shutdown
當(dāng)您運(yùn)行第 3 步時(shí),您應(yīng)該會(huì)在 vsperfmon.exe 中看到一些通知,提示 hello.exe 已啟動(dòng).
When you run step 3, you should see some notification in vsperfmon.exe that hello.exe has started.
如果您計(jì)劃進(jìn)行多次測(cè)試運(yùn)行,則只需運(yùn)行步驟 2-4.換句話(huà)說(shuō),您只需要在二進(jìn)制文件(步驟 1)構(gòu)建后對(duì)其進(jìn)行一次檢測(cè).
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.
這篇關(guān)于如何在命令行中使用 MS 代碼覆蓋工具?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!