Testingprompt onlyMedium

Test Coverage Builder

This loop identifies gaps in test coverage and systematically writes targeted unit/integration tests to increase code coverage. It analyzes coverage reports, prioritizes uncovered code paths, and iterates until the coverage target is achieved, ensuring your codebase remains well-tested without compromising production quality.

← all loops
test-coveragetestingquality-assuranceunit-testscode-qualityautomation

Goal

Increase test coverage to meet the target threshold

How to Run

Activate this loop in your preferred coding agent environment to automatically identify untested code and generate appropriate test cases.

  1. 01

    Launch Coding Agent

    Open your project in Cursor, Claude Code, Codex, OpenCode, or Gemini CLI.

  2. 02

    Activate Loop

    Paste the kickoff prompt provided below into the agent to start the Test Coverage Builder loop.

  3. 03

    Monitor Progress

    Let the agent analyze coverage, write tests, and check results. Review generated tests before committing.

  4. 04

    Exit on Success

    When the exit condition is met, the loop will stop. Manually review any final test changes before merging.

Workflow Steps

  1. 01

    Analyze Current Coverage

    Run npm run test:coverage and parse the output to identify files/functions with low or zero coverage.

  2. 02

    Identify Uncovered Code Paths

    Review source files to understand the logic of uncovered branches, statements, and functions.

  3. 03

    Prioritize Target Areas

    Rank uncovered areas by complexity, risk, and usage frequency to maximize testing impact.

  4. 04

    Write Targeted Tests

    Create or extend test files to cover prioritized uncovered code, focusing on edge cases and typical inputs.

  5. 05

    Verify Coverage Improvement

    Re-run npm run test:coverage to confirm coverage has increased toward the threshold.

  6. 06

    Iterate Until Target Met

    Repeat steps 1-5 up to 10 times or until coverage target is achieved, ensuring steady progress.

Kickoff Prompt

Start the "Test Coverage Builder" loop.

Goal: Increase test coverage to meet the target threshold
Max iterations: 10
Between iterations run: npm run test:coverage
Exit when: Coverage target reached (e.g., 80% line coverage)


Please run 'npm run test:coverage', analyze the coverage report, identify the most critical uncovered code paths, and write corresponding tests using the project's test framework. After each test addition, re-run the coverage check to verify improvement. Continue iterating until the coverage target (e.g., 80% line coverage) is met or max iterations are reached. Focus on meaningful test coverage, not just hitting metrics.

Self-pace this loop. After each iteration, run `npm run test:coverage` and evaluate the output, and only continue if the exit condition is not met (Coverage target reached (e.g., 80% line coverage)). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.

Guardrails

hardcoded
  • ·Do not modify existing production code logic while adding tests.
  • ·Generated tests must be meaningful and not just trivial assertions to hit coverage metrics.
  • ·Avoid breaking existing tests during test additions.
  • ·Run full test suite after each test file creation to ensure stability.
  • ·Prioritize high-risk, complex, or frequently used code paths for testing.
  • ·Ensure all test files follow the project's testing conventions and style guide.

Flow Diagram

rendering…

Related loops — Testing