Testing Your Tests With Code Coverage
summary
Build tests with coverage flags (GCC writes .gcno/.gcda alongside object files), run the test suite (coverage data is cumulative), then run gcov to generate per-file annotated sources that show line counts, hashes for never-executed lines, and a summary percentage. Example run shows 55.56% for a tiny class with uncalled functions g and h and an unused constructor parameter; fill gaps or document unreachable code. Integrate report generation into CI and fail or warn builds when coverage thresholds (e.g. gcov/genhtml) are not met.
AI-written summary · about
chapters (8)
- 0:00Why bother testing? • Testing improves quality
- 2:02Example library/class
- 2:56Example test suite
- 4:45Generating coverage data
- 5:42New file - *.gcda
- 8:06Understanding the coverage report
- 11:03Benefits of checking code coverage
- 14:27Questions?
related talks
43mTest coverage in Go, the whole package
03mTest coverage
22mCollecting Code Coverage With Bazel
31mMeasure End to End Tests Coverage
07mGenerating Coverage with System Test
15mLinux Testing made better with DATA
58mCoverage, quality, and Goodhart's Law
01h 40mTesting, Preconditions, Coverage and Templates in Safety-Critical C++ Code
