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.
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.
- 01
Launch Coding Agent
Open your project in Cursor, Claude Code, Codex, OpenCode, or Gemini CLI.
- 02
Activate Loop
Paste the kickoff prompt provided below into the agent to start the Test Coverage Builder loop.
- 03
Monitor Progress
Let the agent analyze coverage, write tests, and check results. Review generated tests before committing.
- 04
Exit on Success
When the exit condition is met, the loop will stop. Manually review any final test changes before merging.
Workflow Steps
- 01
Analyze Current Coverage
Run npm run test:coverage and parse the output to identify files/functions with low or zero coverage.
- 02
Identify Uncovered Code Paths
Review source files to understand the logic of uncovered branches, statements, and functions.
- 03
Prioritize Target Areas
Rank uncovered areas by complexity, risk, and usage frequency to maximize testing impact.
- 04
Write Targeted Tests
Create or extend test files to cover prioritized uncovered code, focusing on edge cases and typical inputs.
- 05
Verify Coverage Improvement
Re-run npm run test:coverage to confirm coverage has increased toward the threshold.
- 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
Related loops — Testing
Testing
E2E Until Stable
This loop automatically identifies and fixes end-to-end test failures by iteratively running the test suite, analyzing failures, and applying targeted fixes until all tests pass or the maximum iteration limit is reached.
Testing
Regression Prevention Loop
This loop ensures that newly discovered bugs or edge cases are covered by automated regression tests to prevent future incidents. It iterates through identifying missing test coverage, implementing appropriate tests, and validating that the regression suite passes without failures.