Rasmi Ranjan Nayak
Rasmi Ranjan Nayak

Reputation: 11948

How can I get code coverage using gtest on Windows?

I am using gtest for testing my code in C++ with Visual studio 2010. But I could not able to makeout that I have reached 100% code coverage. To make sure that I have covered 100% code coverage, I would like to know that, is there any way to find out the code coverage gtest or not? Because I have Googled a lot but I did not find any possible way to get the code coverage result by using gtest in Windows enviornment. If it is possible please let me know.

Thanks A Lot..

Upvotes: 26

Views: 17153

Answers (2)

OpenCppCoverage
OpenCppCoverage

Reputation: 561

You can try OpenCppCoverage: https://github.com/OpenCppCoverage/OpenCppCoverage.

It is open source, designed for Visual Studio C++ and works well with Google Test. I already used successfully for mid size project (~500 000 lines of code).

Hope that help.

Disclaimer: I am the author of the tool.

Upvotes: 42

Arne Mertz
Arne Mertz

Reputation: 24576

Code coverage in C++ can not be handled by the testing framework solely, because a coverage analysis tool has to know the whole extent of the code (wich the testing framework has not) and it has to instrument the code under test somehow to monitor wich parts of the code get executed.

I had the same desire like you once, wanting to measure my test coverage in MSVC. This is what I learned:
MSVC ships with some command line tools for these instrumentations, googling a bit will get you one or two msdn blog posts about how to use them. Frankly, its not very convenient and easy to use. If you look for third party tools, you will probably not find any free ones. Any tools I found at all were enterprise tools with license fees in the range of several hundred to more than a thousand dollars, so not really an option if you are not a company.

Upvotes: 5

Related Questions