Skip to content

skillTesting

Test Coverage Gap Analysis

Reads the coverage report, ranks uncovered branches by risk and writes meaningful tests for the top gaps instead of chasing a percentage.

npx workspacetemplates add test-coverage-gap-analysis --tool claude-code

Writes 1 file to .claude/skills/test-coverage-gap-analysis/

.claude/skills/test-coverage-gap-analysis/SKILL.md27 lines · 1.6 KBFile
---
name: test-coverage-gap-analysis
description: Reads the coverage report, ranks uncovered branches by risk and writes meaningful tests for the top gaps instead of chasing a percentage.
---

# Test coverage gap analysis

Spend tests where a failure would hurt, not where the percentage is cheapest.

## Steps

1. Generate branch coverage with the project's own tool (`jest --coverage`, `pytest --cov --cov-branch`, `go test -coverprofile`, JaCoCo). Prefer machine-readable output (lcov, JSON, XML).
2. List uncovered files and branches. Add two signals: recent churn (`git log --since=6.months --name-only` counts) and how critical the path is.
3. Rank the top 10 gaps. Weight highest: authorization checks, money and quantity math, data writes and deletes, input validation, error handling and retries, parsing of external data. Weight lowest: logging, getters, generated code, trivial wrappers.
4. For each of the top gaps, write a test that asserts an outcome. Cover the failing branch with a concrete input, not a call that merely executes the line.
5. Rerun coverage and confirm the branch moved. If a test raises coverage but would still pass after you break the code, delete it.
6. Mark code that should not be tested (dead code, generated files) and propose removal or an exclusion with a comment.

## Rules

- Never add assertions like "does not throw" as the only check.
- Never lower a threshold or add ignore pragmas to hit a number.
- One test per behavior, named after it.

## Report

A table of the ranked gaps with the risk reason, the tests written, branch coverage before and after, and the gaps left open.

What it does

A coverage number says how much code ran, not how much is protected. This skill points the agent at the lines that matter: error paths, money, permissions and data changes that no test touches.

It ranks gaps by blast radius and change frequency, writes tests that assert behavior, and reports the result in branches covered rather than a vanity total.

Example

you › Find the riskiest untested code in src/ and cover the top 5

agent › Branch coverage 61 percent. Top gaps: refund() partial-amount branch, requireRole() deny path, importCsv() malformed row, applyTax() zero-rate, session expiry. Wrote 9 tests. Branch coverage in those files went from 38 to 91 percent. Left open: legacy report generator (dead, proposed deletion).

Questions

Why not aim for 100 percent?
The last stretch usually covers trivial code, and a number target invites assertion-free tests. Ranked risk gets more protection per hour spent.
Which coverage tool does it need?
Whatever your project already runs. If none is set up, it proposes the standard one for your language and asks before installing.
  • Contract Testing

    SkillTesting

    Free
  • E2E Test Design

    SkillTesting

    Free
  • Flaky Test Diagnosis

    SkillTesting

    Free