How do I set up code coverage in C++ googletest project in Visual Studio 2010

10,997

Solution 1

You can try OpenCppCoverage: http://opencppcoverage.codeplex.com.

OpenCppCoverage is a code coverage tools for C++ under Windows. It is open-source and works well with google test / Visual Studio C++.

Disclaimer: I am the author of this tool.

Hope that help.

Edit to follow brasofilo advice:

To be more precise about your question, OpenCppCoverage should work with Visual Studio C++ 2010 professional. The only requirement is to support native Pdb files (http://msdn.microsoft.com/en-us/library/yd4f8bd1%28vs.71%29.aspx).

It is open source and free and you can find sources here: https://opencppcoverage.codeplex.com/SourceControl/latest.

What do you mean by portable?

Hope that help.

Solution 2

I think you can use the VSTEST.Consol.exe for this purpose http://msdn.microsoft.com/en-us/library/vstudio/jj155796.aspx. According to documentation, it would run tests written against any test framework. You may enable the /Enablecodecoverage option, which Enables data diagnostic adapter CodeCoverage in the test run.

More information may be found here: http://blogs.msdn.com/b/bhuvaneshwari/archive/2012/06/16/vstest-console-exe-commandline-test-runner.aspx

There is also an open source code coverage tool called ggcov: http://ggcov.sourceforge.net/index.html

Hope that these helps.

Share:
10,997

Related videos on Youtube

Janik Zikovsky
Author by

Janik Zikovsky

Updated on August 17, 2022

Comments

  • Janik Zikovsky
    Janik Zikovsky over 1 year

    I have a C++ googletest project building in Visual Studio 2010 professional. This builds a console application which generates XML test result output. How can I set it up to get code coverage information?

    I have tried instructions here to instrument the code but viewing the Code Coverage results seems to require Visual Studio Ultimate. Is there any converter for the .coverage files Visual Studio generates?

    Bonus points for portable/free/open-source solutions!

  • brasofilo
    brasofilo over 9 years
    Please, tailor each answer according to the question in question, copy pasting the same answer around won't cut it, disclaimer or not disclaimer.
  • Mawg says reinstate Monica
    Mawg says reinstate Monica over 8 years
    @OpenCppCoverage Great to see that your project is still alive - last update 4 days ago. I notice that you have a command line interface - could the tool be used by Windows coders who do not use MSVC and still generate HML output? Is it FOSS? Could it be rebuilt for use on Linux? Is it based primarily on gcov (and maybe lcov) and just re-wrapped as an MSVC plugin? Any plans for a Linux version, or objections to a fork if it is FOSS?