Skip to content
agentusehub
Sign in+ Submit
Generate missing unit tests for untested modules
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.

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

The problem it solves

“Generate missing unit tests for untested modules” is an advanced Coding AI agent workflow from Software. It connects Claude Code, GitHub Copilot and Slack in 7 steps. Setup takes about 2 hours, running costs are about $20/mo and it saves roughly 6 hours a week.

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.

Frequently asked questions

What does the “Generate missing unit tests for untested modules” workflow do?

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

Which tools do I need?

You need Claude Code, GitHub Copilot and Slack. Claude Code: reads the coverage report, writes tests, runs them and fixes failures. GitHub Copilot: reviews the generated test PRs for weak or duplicated assertions. Slack: receives the weekly coverage change for the engineering channel.

How long does it take to set up?

Plan for about 2 hours. It is rated advanced. The guide walks through 7 steps, starting with “Generate a coverage summary”.

How much does it cost to run?

Expect about $20/mo in running costs (Under $25/mo range).

How much time does it save?

About 6 hours a week, as reported for this setup. 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.

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
Add this badge to your site

Built this workflow? Show it is featured on AgentUseHub with a live upvote count that links back here. About badges

Featured on AgentUseHub