Introduction to Code-Coverage
Code-Coverage is a measure used in the Software-Development-Lifecycle to describe the degree to which the source code of a program is executed when a particular test suite runs. It is a key metric in Software-Testing and Quality-Assurance. By using Code-Coverage analysis, developers can identify parts of the codebase that are not being exercised by Unit-Testing, which helps in reducing the risk of bugs in production. According to Martin Fowler, coverage is a tool to find untested code, not a goal in itself.
Core Coverage Metrics
Different metrics provide different perspectives on the thoroughness of the tests:
- Statement Coverage: Measures whether each statement in the code has been executed.
- Branch Coverage: Ensures that all possible branches of control structures (like if-else) are covered.
- Function Coverage: Tracks whether every function or method has been called.
- Condition Coverage: Checks whether each boolean sub-expression has been evaluated to both true and false.
Tools and Continuous-Integration
Modern development teams integrate Code-Coverage tools directly into their Continuous-Integration pipelines. Popular tools include Istanbul for JavaScript, JaCoCo for Java, and Cobertura. These tools generate detailed reports that can be analyzed during Static-Analysis to maintain high standards of code health. For more information, visit the Wikipedia page on Code Coverage.