Glossary

Code Coverage

Code coverage is a metric that measures the percentage of code that is executed by automated tests.

Code coverage is a metric that measures the percentage of code executed by automated tests. It's a key indicator of test suite quality: a high percentage means most of the code is tested, a low percentage means most of it isn't.

While code coverage is a useful metric, it's not a guarantee of quality: a high percentage doesn't mean the code is bug-free. Write tests that cover all possible code paths and edge cases so the code is thoroughly tested, rather than chasing a high percentage for its own sake.

Code coverage is measured as a percentage: 100% means every line of code is executed by the test suite.

Code coverage can be calculated in various ways, such as line coverage, branch coverage, and path coverage. It can also be calculated based on methods, conditions and statements, or lines. OtterWise generally calculates by lines: for every line containing a statement (not documentation, a function declaration, an import, and so on), it checks whether the tests execute it. If every line is covered, you get 100%. We also support going by methods, conditions, and statements, which means it also checks if a method is called. This can be misleading, because empty methods (`function test() {}`) count toward coverage despite having nothing to test. For this reason, we don't recommend using this method for calculating code coverage, and it's not enabled by default.

Related Concepts: Code coverage is often discussed alongside test coverage, and is an important part of continuous testing strategies. It's also related to static analysis tools that help improve code quality.

To learn more about how code coverage relates to other quality metrics, you might also be interested in cyclomatic complexity and technical debt.

Ready when you are

Ship better code faster, with confidence.

PR comments, status checks, line annotations, and trends, all without code access. Free for public repos; per-repo pricing for private repos.