BoilerPrompt
Claude Code

Claude Code prompt to write unit tests

This prompt turns Claude Code loose on your coverage gaps: it runs the coverage report first, picks the pure-logic modules where unit tests pay off most, and writes cases for boundaries and error paths, not just happy paths. Each new file is executed in isolation and against the full suite before the agent reports back.

Last updated

Prompt
Write unit tests for the untested modules in this codebase. Start by running the existing test command with coverage to find the gaps, then prioritize pure logic: parsers, formatters, price or date calculations, permission checks. For each target module write cases for the documented behavior, boundary inputs (empty arrays, zero, negative numbers, unicode strings), and the error paths that throw or return early. Mock only true externals like network and filesystem; do not mock the module under test's own collaborators unless construction is impractical. Match the assertion style already used in the repo. Skip snapshot tests unless one already exists for that area. After writing each file, run it in isolation, then run the whole suite to confirm nothing else broke. Finish with a short table: module, cases added, and uncovered branches that still remain with the reason.

Same task in other tools

Questions about this prompt

Why run coverage before writing any tests?

It stops the agent from testing whichever file it happened to read last. The report gives it real targets, and gives you a before-and-after number to check its summary against.

Claude Code mocks everything, even simple value objects. How do I stop that?

The "mock only true externals" line prevents most of it. If it persists, name the collaborators that must stay real, for example "construct the actual Money and Clock classes, mock only the HTTP client".

Can I target one module instead of letting it choose?

Swap the first sentence for the file path and keep the boundary and error-path instructions unchanged. Per-module runs produce smaller diffs, which is usually worth the extra prompts on a big backlog.

Related prompts