Test quality Recommended
Treat coverage as a floor
Use line and branch coverage to find untested code and to stop it falling. Never treat a high number as proof of good tests.
How to do it
Set a minimum at today's coverage, rounded down to a whole number, in the runner, such as Vitest coverage.thresholds, Jest coverageThreshold or pytest-cov --cov-fail-under. Raise it as coverage grows. Read the report for risky code with no tests, rather than chasing a total.
Example
// vitest.config.js
export default {
test: {
coverage: { provider: 'v8', thresholds: { lines: 80, branches: 75 } },
},
};
# pyproject.toml for pytest-cov and coverage.py
[tool.coverage.run]
branch = true
[tool.coverage.report]
fail_under = 80
// build.gradle.kts with JaCoCo for Java and Kotlin
tasks.jacocoTestCoverageVerification {
violationRules { rule { limit { minimum = "0.80".toBigDecimal() } } }
}
tasks.check { dependsOn(tasks.jacocoTestCoverageVerification) }
How to check
The test run fails when coverage falls below the set minimum.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/test-quality/coverage-floor.