Test Coverage & SimpleCov
Coverage metrics help us focus testing effort, highlight dead code, and track regressions. SimpleCov integrates seamlessly with both Minitest and RSpec.
Configure SimpleCov
Use branch coverage to catch missing conditionals. Adjust `minimum_coverage` carefully—enforce attainable targets (e.g., 90%) and build culture around meaningful tests, not gaming metrics.
Interpreting coverage reports
HTML report
Open `coverage/index.html` to see per-file metrics, branch misses, and hotspots. Lines highlighted in red need tests; yellow indicates partial coverage.
Trending metrics
Export coverage summaries as JSON (`SimpleCov::Formatter::JSONFormatter`) and push to Datadog or GitHub Checks for trend tracking in CI.
Strategy for meaningful coverage
- Prioritize business-critical modules (`app/services`, `app/queries`). We group them in SimpleCov to keep the dashboard actionable.
- Exclude auto-generated files (`config/`, `db/schema.rb`, vendor code) to prevent noisy metrics.
- Set a threshold delta in CI—fail builds if coverage drops by more than 0.5% compared to main.
- Use branch coverage to detect missing `else` clauses or guard branches.
Automation tips
- Run coverage on nightly builds to keep feedback fast for local TDD loops; optional in every PR if performance permits.
- Upload coverage from parallel CI runs using `simplecov-cobertura` to merge results.
- Surface coverage failures prominently in PR templates so reviewers can request missing tests before merge.