mcpField

Coverage Until Threshold

FeaturedOn demand
TestingUp to 12 rounds

About Coverage Until Threshold

This loop raises test coverage to a target threshold, 80% by default. Each round runs the tests with coverage, finds under-covered code, writes tests for it and measures again. It stops after at most 12 rounds.

Key features

  1. 01Default coverage threshold of 80%
  2. 02Requires every test to pass as well
  3. 03Capped at 12 rounds to avoid endless runs
  4. 04Started manually in Claude Code

Use cases

  1. 01Filling coverage gaps in modules that lack tests
  2. 02Meeting a coverage requirement before merging
  3. 03Building a test safety net ahead of a refactor
Goal
Coverage reaches the target threshold (default 80%) and all tests pass.
Exit when
Stop when coverage meets the threshold and npm test -- --coverage exits with code 0.
Between iterations run
npm test -- --coverage

Launch prompt

Paste into Claude Code. The agent repeats the steps below until the exit condition is met.

prompt.md
Start the "Coverage Until Threshold" loop.
Goal: Coverage reaches the target threshold (default 80%) and all tests pass.
Max iterations: 12.
Step 1: Measure coverage — Run the tests with coverage, read the report and identify files and branches that fall below the threshold. `npm test -- --coverage`
Step 2: Write missing tests — Add or improve tests for the under-covered code, starting with the largest gaps, without breaking existing tests.
Step 3: Re-measure — Run the tests with coverage again and compare the result with the threshold. If coverage is still short or a test fails, begin another round. `npm test -- --coverage`
Between iterations run: `npm test -- --coverage`
Exit when: Stop when coverage meets the threshold and npm test -- --coverage exits with code 0.

Steps

Each round runs in order; if the exit condition isn’t met, another round starts, up to 12.

01
Measure coverage

Run the tests with coverage, read the report and identify files and branches that fall below the threshold.

$npm test -- --coverage
02
Write missing tests

Add or improve tests for the under-covered code, starting with the largest gaps, without breaking existing tests.

03
Re-measure

Run the tests with coverage again and compare the result with the threshold. If coverage is still short or a test fails, begin another round.

$npm test -- --coverage
Not met → next roundExits when met

Supported agents

Coding agents that can run this loop directly.

Claude Code
Cursor

Comments

Markdown supported