Skip to content
Latchkey

How to Enable Branch Coverage vs Line Coverage in CI

Line coverage counts executed lines; branch coverage checks that each conditional path is exercised.

Enable branch mode explicitly: coverage.py branch = true, Go -covermode=atomic, and Jest already tracks branches via the branches threshold. Branch coverage catches an untested else a line metric would miss.

coverage.py (branch on)

.coveragerc
[run]
branch = true
source = ["myapp"]

Jest (branch threshold)

jest.config.js
module.exports = {
  coverageThreshold: {
    global: { lines: 80, branches: 80 },
  },
};

Gotchas

  • Branch coverage is always lower than line coverage on the same code; set thresholds accordingly.
  • A line can be fully covered while one of its branches is never taken, which is exactly what branch mode surfaces.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →