I came up a batch file to generate code coverage file as is written in this post.
cl /Zi hello.cpp -link /Profile
vsinstr -coverage hello.exe
start vsperfmon /coverage /output:run.coverage
hello
vsperfcmd /shutdown
However, I got this error message when I run the batch file.
I had to run vsperfcmd /shutdown
manually to finish it.
What might be wrong?
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.
Code coverage tools are available for many programming languages and as part of many popular QA tools. They are integrated with build tools like Ant, Maven, and Gradle, with CI tools like Jenkins, project management tools like Jira, and a host of other tools that make up the software development toolset.
To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.
In Visual Studio, to use the code coverage tool, you right click on a test in the Test Explorer and then choose Analyze Code Coverage for Selected Test. This would look at the code paths for this one unit test. Typically, you run code coverage on the entire project to verify that all your code paths are being run.
This is just a timing issue.
The start vsperfmon /coverage /output:run.coverage
command starts up vsperfmon.exe in a separate process.
Concurrently, your script goes on to run hello
. If hello
is a really simple program, it is possible that it executes and completes before vsperfmon.exe is running and fully initialized. If your script hits vsperfcmd /shutdown
before the monitor is up and running, you will get the error you're showing.
vsperfcmd
is just a controller/launcher for vsperfmon
, so you can use that exclusively in your batch file:
cl /Zi hello.cpp -link /Profile
vsinstr -coverage hello.exe
vsperfcmd /start:coverage /output:run.coverage
hello
vsperfcmd /shutdown
In this case, the first call to vsperfcmd
will block until the monitor is up and fully running.
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