Skip to content
agentusehub
CodingAdvancedSoftware

Generate missing unit tests for untested modules

Claude Code reads your coverage report, picks the riskiest untested modules and writes unit tests that pass, one small PR at a time.

Time saved
6h / week
Setup time
2 hours
Running cost
$20/mo
Cost range
Under $25/mo

The problem it solves

Most codebases have a few critical modules with little or no test coverage, usually because they were written under deadline. Nobody wants to go back and write tests for old code, so every change to those files is a gamble. Coverage sits at the same number quarter after quarter.

How it flows
  1. Run coverage
  2. Pick 3 riskiest files
  3. Write + run tests
  4. Open small PRs

Step-by-step setup

  1. Generate a coverage summary

    Run your suite with a JSON summary reporter, for example vitest run --coverage --coverage.reporter=json-summary or jest --coverage --coverageReporters=json-summary. This writes coverage/coverage-summary.json for Claude Code to read.

  2. Document testing rules in CLAUDE.md

    Add a Testing section covering your framework, file naming (src/lib/foo.ts maps to tests/lib/foo.test.ts), how to mock the database and which helpers live in tests/utils. Claude Code reads CLAUDE.md at the start of every session.

  3. Rank targets by risk

    Use the ranking prompt below to list files under 50% line coverage, sorted by how often they changed in the last 90 days. Start with the top three; frequently edited, untested code is where bugs come from.

  4. Write tests on a branch per module

    Run the test-writing prompt in a fresh branch for each file. Claude Code writes the tests, runs them and iterates until they pass, without touching the source file.

  5. Prove the tests can fail

    Ask Claude Code to temporarily break one line in the source, confirm at least one new test fails, then revert. This catches tests that only assert a value is defined.

  6. Open one PR per module

    Keep each PR under 400 lines so reviewers actually read it, and request a Copilot review to spot redundant cases.

  7. Run it every Friday

    Schedule the same flow in CI with claude -p (headless mode) on one module per week, and post the before and after coverage to #engineering through a Slack incoming webhook.

Example prompts

Rank coverage gaps
Read coverage/coverage-summary.json. List every file under src/ with line coverage below {{threshold}}%.

For each file, count how many commits touched it in the last 90 days using git log --since=90.days --name-only.

Return a table sorted by commit count, highest first, with columns: file, line coverage, commits (90d), and a one-sentence note on what the file does.

Exclude generated files, type-only files and anything under src/migrations.
Write tests for one module
Read {{file_path}} and any existing tests for it in {{test_dir}}. Read CLAUDE.md for our testing conventions.

Write unit tests that cover:
- the normal path of every exported function,
- edge cases: empty inputs, nulls, boundary values, very large inputs,
- every thrown error and rejected promise.

Rules:
- Do not modify {{file_path}}. If something cannot be tested without a change, stop and explain why.
- Mock only the network, database and clock. Never mock the module under test.
- Name tests in the form "returns X when Y".
- Run the tests after writing them and fix failures until they all pass.

Finish by reporting line coverage for {{file_path}} before and after.
Coding · Advanced
  1. Write migration plan
  2. Agent edits in batches
  3. Tests per batch

Ship a 40-file refactor with a coding agent

Plan, execute and review a cross-cutting refactor in small batches, with Claude Code making the edits and GitHub Copilot reviewing each PR.

Claude Code · GitHub Copilot
Coding · Intermediate
  1. PR opened
  2. Copilot inline review
  3. Claude risk summary

Automated first-pass review on every pull request

Copilot and Claude review each PR for bugs, missing tests and risky changes before a human looks, so reviewers can focus on design.

GitHub Copilot · Claude · Slack
Sales · Beginner
  1. Form submit
  2. Fetch company site
  3. Claude scores fit

Auto-qualify inbound leads before a rep sees them

Score every demo request against your ICP, update HubSpot and ping the right rep in Slack within a minute of the form submit.

n8n · Claude · HubSpot · Slack