Home / Learn Embedded C / Code Coverage for Embedded Projects
Code Coverage for Embedded Projects
Measuring how much of the codebase is actually exercised by the existing test suite.
How to think about this
Definition
Code coverage measures what percentage (and which specific lines/branches) of the codebase are actually exercised when the test suite runs, helping identify untested code paths — particularly valuable for finding error-handling branches that normal, successful-path testing tends to miss.
Why you need this
High code coverage does not guarantee correctness (tests can exercise a line without actually checking its result is right), but LOW coverage reliably reveals code paths with zero verification at all — coverage is a useful signal for finding testing gaps, not a complete substitute for test quality.
How it works
Coverage tools typically instrument the compiled test binary to record which lines/branches executed during a test run, then report this against the full source — for embedded projects, this is usually applied to host-based tests of the logic layer, where the tooling is most mature and practical.
Where you'll see this
- Test suite quality assessment
- Finding untested error paths
- QA process metrics
Try it
Only calling classify(5) leaves 2 of 3 branches completely unexercised — exactly the kind of gap a real coverage tool would flag automatically.
Try it: 100% coverage with a weak, nearly-useless assertion
This "test" executes every line of divide_safe once (100% line coverage) but never actually checks the result is correct or exercises the b==0 branch — exactly the false confidence this lesson warns about.
Test what you just read
1. What is a key limitation of code coverage as a quality metric?
Coverage only tells you a line ran during testing, not that the test actually verified it behaved correctly — it is a gap-finding tool, not a correctness guarantee.