Queen of Code Logo
Melissa BenuaQueen of Code
Back to all posts

Who Needs Code Coverage?

Understanding when code coverage metrics help and when they hurt your testing strategy

January 22, 2020
3 min read
Testing
Code Coverage
Software Quality
Metrics
Who Needs Code Coverage?
Melissa Benua

Melissa Benua

Engineering Leader & Speaker

Code coverage is one of the most widely tracked metrics in software development. Teams proudly display their coverage percentages in READMEs and dashboards, organizations set coverage thresholds as quality gates, and developers strive to maintain or increase these numbers with each commit. But in our pursuit of higher percentages, we often lose sight of a fundamental question: What does code coverage actually tell us about quality?

What Code Coverage Is (and Isn't)

At its core, code coverage is a measure of which lines, branches, or functions in your code have been executed during tests. Nothing more, nothing less. It tells you:

  • Which parts of your code were touched by your tests
  • Which parts were never executed during testing

It does not tell you:

  • Whether your tests are meaningful
  • If you're testing the right behaviors
  • How well your code handles edge cases
  • If your tests accurately reflect real-world usage

The Value of Coverage Metrics

Despite these limitations, code coverage provides meaningful benefits:

Finding Dead Spots

Low coverage areas highlight code that might never have been tested, revealing potential risk areas that need attention.

Enforcing Testing Discipline

Requiring a minimum coverage threshold encourages developers to think about testability and write tests alongside their code.

Tracking Testing Trends

Declining coverage over time can signal degrading test discipline, while improving coverage can reflect growing test maturity.

The Pitfalls of Coverage Obsession

However, an excessive focus on coverage percentages can lead to counterproductive behaviors:

Test Quantity Over Quality

Writing tests solely to increase coverage often results in low-value tests that exercise code without verifying meaningful behavior.

False Confidence

High coverage can create a false sense of security when tests aren't actually verifying important functionality.

Gaming the System

Teams may manipulate coverage by excluding difficult-to-test code or writing simplistic tests that execute code without making meaningful assertions.

"I would rather have 70% coverage of the critical parts of my application than 100% coverage of trivial code."

A More Balanced Approach

Rather than fixating on a single percentage, consider these alternative approaches:

  1. Risk-based coverage: Focus testing efforts on high-risk, high-impact areas of your code.

  2. Criticality weighting: Assign higher importance to coverage in core business logic than in boilerplate code.

  3. Mutation testing: Use tools that deliberately introduce bugs to see if your tests catch them.

  4. Multiple coverage dimensions: Track line, branch, and path coverage for a more complete picture.

  5. User-centered test coverage: Prioritize covering the paths your users actually take through your software.

Practical Guidelines

For teams looking to use coverage effectively:

  • Set reasonable thresholds: 80-85% is often sufficient; higher demands diminishing returns
  • Emphasize critical path coverage: Ensure 100% coverage of your most important business logic
  • Review test quality: Regularly examine tests for meaningfulness, not just quantity
  • Use coverage as a conversation starter: Let low coverage prompt discussions about risk, not automatic fixes
  • Complement with other metrics: User-reported defects, test execution time, and code complexity provide additional context

Conclusion

Code coverage is a useful but limited tool in your quality arsenal. Used wisely, it helps identify untested code and maintain testing discipline. But when elevated to an end rather than a means, it can distract from the true goal: building software that reliably delivers value to users.

The next time someone asks "What's your coverage percentage?" respond with a better question: "What risks are our tests helping us mitigate?"

Related Posts

Integration Tests: What's in a Name?

What is an integration test? And why is it critical to our continuous delivery efforts?

Melissa on WeHackPurple Podcast!

An engaging discussion on security, testing, and engineering leadership