Skip to content

commandTesting

Coverage Gaps

Runs coverage, ranks the riskiest untested code by what breaks if it fails, and writes tests for the top items.

npx workspacetemplates add coverage-gaps --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/coverage-gaps.md15 lines · 1.1 KBFile
---
description: Runs coverage, ranks the riskiest untested code by what breaks if it fails, and writes tests for the top items.
argument-hint: "[folder or module, default all]"
---

Find and close coverage gaps. Scope: $ARGUMENTS (whole project if empty).

1. Run the project's coverage command (jest --coverage, vitest --coverage, pytest --cov, go test -cover, dotnet test with coverlet, cargo llvm-cov). If none is configured, suggest the smallest setup and ask before adding it.
2. Record the overall and per-file figures, including branch coverage if available.
3. Rank uncovered code by risk: money, auth, data writes and parsing first, then branching complexity, then recent change frequency (check `git log --since=3.months --name-only`). Ignore generated code, types and trivial getters.
4. Show the top 10 gaps with file, uncovered lines or branches, and why each is risky.
5. Write tests for the top 3, following the existing style. Assert behavior, not implementation details. Do not add tests whose only purpose is to touch lines.
6. Rerun coverage and compare.

Report before and after per file and list the remaining gaps. Ask before committing.

What it does

A coverage percentage says little; what matters is which uncovered lines carry risk. This command runs the coverage tool, then ranks the gaps by how important and how complicated the code is.

It writes tests for the top few gaps and reports the numbers before and after, so you see the change instead of a vanity figure.

Example

you › /coverage-gaps src/billing

agent › Billing: 54% lines, 41% branches.
Top gaps: prorate() (no tests, money), refund.ts error branch, tax.ts rounding.
Added 14 tests for the top 3. Billing now 83% lines, 76% branches.
Commit the new tests?

Questions

Does it aim for 100%?
No. It targets risky code and says which lines are not worth testing.
Will it install a coverage tool?
Only after asking, and it suggests the smallest setup.
  • Add Edge Case Tests

    CommandTesting

    Free
  • Add Regression Test

    CommandTesting

    Free
  • E2E Scenario

    CommandTesting

    Free
  • Fix Failing Tests

    CommandTesting

    Free