This tutorial describes how to produce test-coverage metrics for C/C++ projects. We start by instrumenting an autotools build to produce gcov
output with gcc
; we then generate test coverage artifacts by running our test suite, and finally we explore our results using lcov
.
Introduction
We’d like to assess the quality of the existing test suite for each Product Strategy project. A measurement of test coverage will tell us what part of the project’s code is “covered” or exercised by its tests. 50% is a start; 80% would be a good goal for a neglected project; one rarely encounters 100% test coverage, but we’d like to get as close as we can. Initially we’ll use these findings to gain an overview of the test-quality of each project; ultimately these metrics will guide the improvement of our codebase, and enable us to monitor our progress using Jenkins and associated open-source tools.
A Three-Part Process in Several Steps
We’ll enable test-coverage of a particular C/C++ project in a three-part process:
- enabling a special build
- running the tests
- studying the output
Our first step will be to enable a special build. Ultimately this just means adding a few flags to our gcc
invocation, but it never seems so straightforward with autotools projects Read more