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);
}
I compiled it to get the execution
cl /Zi hello.cpp -link /Profile
Then, I instrument the execution and generated the .coverage binary.
vsinstr -coverage hello.exe
start vsperfmon -coverage -output:mytestrun.coverage
vsperfcmd -shutdown
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.
On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.
You should now have a folder named "CodeCoverage" in the same folder where you executed the above command. OpenCover generates a file named "results. xml" which contains the code coverage information. This files contains a lot of information but isn't very readable.
To see code coverage for your test, click the three-bars icon that's next to your Org alias at the bottom of VS Code and open the class or trigger that you're testing. Click the the three-bars icon to toggle between enabling and disabling code coverage highlighting.
You need to run your program after the monitor starts:
> vsinstr /coverage hello.exe
> start vsperfmon /coverage /output:mytestrun.coverage
> hello.exe
> vsperfcmd /shutdown
When you run step 3, you should see some notification in vsperfmon.exe that hello.exe has started.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With