Code Coverage

Code Coverage

Code coverage is a metric that measures the percentage of code that is executed by automated tests. It is an essential metric for assessing the quality of a test suite. A high code coverage percentage indicates that most of the code is tested, while a low code coverage percentage indicates that most of the code is not tested.

While code coverage is a useful metric, it is not a guarantee of quality, and a high code coverage percentage does not necessarily mean that the code is bug-free. It is possible to have a high code coverage percentage and still have bugs in the code. Keep in mind to write tests that cover all possible code paths and edge cases to ensure that the code is thoroughly tested, not aim needlessly for a high code coverage percentage.

Code coverage is measured as a percentage, with 100% code coverage indicating that every line of code is executed by the test suite.

Code Coverage can be calculated in varius 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, so for every line that contains a statement (non-documentation, non-function declaration, non-import, etc.), it is checked if it is executed by the tests, and if all of these lines/statements are 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 sometimes seem misleading because empty methods (`function test() {}`) count in the coverage, despite having nothing to test. For this reason, we don't recommend using this method for calculating code coverage and it is not enabled by default.

Improve code quality today_

With OtterWise, you can track Code Coverage, test performance, contributor stats, code health, and much more.