問題描述
我有以下 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
然后,我檢測執(zhí)行并生成 .coverage 二進制文件.
Then, I instrument the execution and generated the .coverage binary.
vsinstr -coverage hello.exe
start vsperfmon -coverage -output:mytestrun.coverage
vsperfcmd -shutdown
當我在 VS2010 中打開覆蓋文件時,我沒有得到任何結(jié)果.
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.
推薦答案
你需要在監(jiān)視器啟動后運行你的程序:
You need to run your program after the monitor starts:
- <代碼>>vsinstr/coverage hello.exe
- <代碼>>啟動 vsperfmon/coverage/output:mytestrun.coverage
- <代碼>>你好.exe
- <代碼>>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)構(gòu)建后對其進行一次檢測.
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 代碼覆蓋工具?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!