About Code Coverage

What is code coverage?

Code coverage is a measurement used to express which lines of code were executed by a test suite. We use three primary terms to describe each line executed.

  • hit indicates that the source code was executed by the test suite.
  • partial indicates that the source code was not fully executed by the test suite; there are remaining branches that were not executed.
  • miss indicates that the source code was not executed by the test suite.

Coverage is the ratio of hits / (sum of hit + partial + miss). A code base that has 5 lines executed by tests out of 12 total lines will receive a coverage ratio of 41% (rounding down).

Phrased simply, code coverage provides a visual measurement of what source code is being executed by a test suite. This information indicates to the software developer where they should write new tests in an effort to achieve higher coverage.

Testing source code helps to prevent bugs and syntax errors by executing each line with a known variable and cross-checking it with an expected output.

What does Codecov bring to the table?

Code coverage tools incentivize developers to write tests and increase coverage. During the process of writing tests, the developer may discover new bugs or syntax issues in the source code that are important to resolve before distributing the application.

Codecov takes coverage to the next level. Unlike open source and paid products, Codecov focuses on integration and promoting healthy pull requests. Codecov delivers or "injects" coverage metrics directly into the modern workflow to promote more code coverage, especially in pull requests where new features and bug fixes commonly occur.

Top 5 Codecov Features

  1. Pull Request Comments
  2. Commit Status (e.g., PR blocking)
  3. Merging Reports
  4. Flags e.g. #unittests vs #functional and Carryforward Flags for partial CI builds
  5. Path manipulation: Ignoring paths, fixing paths, path regexp

What’s Next

For more information about code coverage: https://en.wikipedia.org/wiki/Code_coverage