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
How to Fail CI Under a Jest Coverage ThresholdEnforce a minimum coverage level in CI with Jest coverageThreshold, so the test command exits non-zero when l…
How to Generate pytest Coverage in CIMeasure Python test coverage in CI with pytest-cov, running pytest --cov to print a report and emit coverage.…
How to Exclude Files From Coverage in CIKeep generated code, tests, and vendored files out of coverage numbers with per-tool exclude patterns so the…