Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I measure CppUnit test coverage (on win32 and Unix)?

Tags:

I have a very large code base that contains extensive unit tests (using CppUnit). I need to work out what percentage of the code is exercised by these tests, and (ideally) generate some sort of report that tells me on a per-library or per-file basis, how much of the code was exercised.

Here's the kicker: this has to run completely unnatended (eventually inside a continuous integration build), and has to be cross platform (well, WIN32 and *nix at least).

Can anyone suggest a tool, or set of tools that can help me do this? I can't change away from CppUnit (nor would I want to - it kicks ass), but otherwise I'm eager to hear any recommendations you might have.

Cheers,

like image 250
Thomi Avatar asked Aug 28 '08 18:08

Thomi


People also ask

How is test coverage measured?

How to Calculate Test Coverage. Calculating test coverage is actually fairly easy. You can simply take the number of lines that are covered by a test (any kind of test, across your whole testing strategy) and divide by the total number of lines in your application.

What tool is used to measure code coverage?

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.

How do you check vs test coverage?

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.

How do I get code coverage results?

Code coverage results are displayed in the Coverage tool window, in the Project tool window, and in the editor after you run at least one configuration with coverage. Results of the code coverage analysis are saved to the coverage folder in the IDE system directory.


2 Answers

Which tool should I use?

This article describes another developers frustrations searching for C++ code coverage tools. The author's final solution was Bullseye Coverage.

Bullseye Coverage features:

  • Cross Platform Support (win32, unix, and embedded), (supports linux gcc compilers and MSVC6)
  • Easy to use (up and running in a few hours).
  • Provides "best" metrics: Function Coverage and Condition/Decision Coverage.
  • Uses source code instrumentation.

As for hooking into your continuous integration, it depends on which CI solution you use, but you can likely hook the instrumentation / coverage measurement steps into the make file you use for automated testing.


Testing Linux vs Windows?

So long as all your tests run correctly in both environments, you should be fine measuring coverage on one or the other. (Though Bullseye appears to support both platforms). But why aren't you doing continuous integration builds in both environments?? If you deliver to clients in both environments then you need to be testing in both.

For that reason, it sounds like you might need to have two continuous build servers set up, one for a linux build and one for a windows build. Perhaps this can be easily accomplished with some virtualization software like vmware or virtualbox. You may not need to run code coverage metrics on both OSs, but you should definitely be running your unit tests on both.

like image 103
Justin Standard Avatar answered Oct 09 '22 09:10

Justin Standard


If you can use GNU GCC as your complier, then the gcov tool works well. It's very easy to fully automate the whole process.

like image 40
Imbue Avatar answered Oct 09 '22 08:10

Imbue