Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 873
Janik Zikovsky Avatar asked Apr 08 '13 14:04

Janik Zikovsky


2 Answers

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?

  • If you mean "Multi platform" -> No, it works only on Windows
  • If you mean "Portable application" (http://en.wikipedia.org/wiki/Portable_application): OpenCppCoverage required only Redistributable for Visual Studio 2013 to be installed on host (http://www.microsoft.com/en-US/download/details.aspx?id=40784) but it does not write to registry and you can move the binaries where you want (usb key for example).

Hope that help.

like image 160
OpenCppCoverage Avatar answered Nov 06 '22 23:11

OpenCppCoverage


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.

like image 43
taocp Avatar answered Nov 06 '22 22:11

taocp