Determining Code Coverage
Explore how to determine code coverage using Jest in your React applications. Understand the different coverage metrics like statement, branch, function, and line coverage. Learn to generate detailed coverage reports and add missing tests to improve coverage while acknowledging that full coverage doesn’t guarantee bug-free code.
Understanding code coverage
Code coverage defines the amount of source code covered by tests. It allows us to identify gaps in our test suite quickly.
Jest gives us the following coverage statistics for each source file:
-
Statement coverage: How many of the source code statements have been executed during test execution?
-
Branch coverage: How many of the branches of conditional logic (for example,. branches in an
ifstatement) have been executed during test execution? -
Function coverage: How many of the functions have been called during test execution?
-
Line coverage: How many lines of source code have been executed during test execution?