Search code examples
c++visual-studio-2010unit-testingcode-coveragegoogletest

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..


Solution

  • 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.