Coverage Delta Gate Workflow
Gate merges on coverage of changed lines rather than a global percentage so new code is tested without blocking on legacy debt.
Objective
Enforce coverage on changed code rather than an absolute global target.
Environment
- A coverage tool with diff support
- CI pipeline
- A global coverage baseline
Steps
1. Measure coverage of changed lines
Compute coverage restricted to the lines changed in the pull request.
Expected state: Changed-line coverage is known.
2. Gate on the delta
Require changed-line coverage above a threshold instead of a global percentage.
Expected state: New code is tested without fighting legacy debt.
3. Allow documented exceptions
Permit justified exclusions for generated or trivial code.
Expected state: Legitimate exclusions are explicit.
4. Track the global trend
Also monitor overall coverage so it does not slide.
Expected state: Global coverage holds or improves.
Decision points
Global percentage or changed lines?
- Changed-line coverage
- Global percentage
Gate changed lines; global gates block on unrelated legacy debt.
Allow exclusions?
- Allow with justification
- Never allow
Allow documented exclusions for genuinely untestable code.
Expected outcome
New and changed code is adequately tested while legacy coverage debt is not a blocker.
Verification
Confirm a change with untested new lines fails the gate and justified exclusions are documented.
Cleanup
Review exclusions periodically to prevent them becoming permanent holes.
Overview
Enforce coverage on changed code rather than an absolute global target.
This workflow is reusable across teams and environments; adapt the commands to your tooling while keeping the sequence and checkpoints intact.
Environment and prerequisites
- A coverage tool with diff support
- CI pipeline
- A global coverage baseline
Procedure
1. Measure coverage of changed lines
Compute coverage restricted to the lines changed in the pull request.
Expected state: Changed-line coverage is known.
2. Gate on the delta
Require changed-line coverage above a threshold instead of a global percentage.
Expected state: New code is tested without fighting legacy debt.
3. Allow documented exceptions
Permit justified exclusions for generated or trivial code.
Expected state: Legitimate exclusions are explicit.
4. Track the global trend
Also monitor overall coverage so it does not slide.
Expected state: Global coverage holds or improves.
# diff coverage on changed lines only
diff-cover coverage.xml --compare-branch=origin/main --fail-under=80
Verification
Confirm a change with untested new lines fails the gate and justified exclusions are documented.
Decision points
Global percentage or changed lines?
- Changed-line coverage
- Global percentage
Recommendation: Gate changed lines; global gates block on unrelated legacy debt.
Allow exclusions?
- Allow with justification
- Never allow
Recommendation: Allow documented exclusions for genuinely untestable code.
Common failures
- Global gates block unrelated work.
- Undocumented exclusions hide gaps.
- Ignoring the global trend lets coverage slide.