BoilerPrompt
Cursor

Cursor prompt to write unit tests

Instead of asking for "some tests" and getting happy-path filler, this prompt makes Cursor map every branch of the module first, then write cases against each conditional with real assertions rather than snapshots. The coverage run at the end surfaces the lines still untested, so you can see exactly what the suite proves.

Last updated

Prompt
Write unit tests for the module I have open, or ask me which file if nothing is selected. First read the module and its imports to map every branch: happy paths, error paths, boundary values, and early returns. Use the test runner already configured in this repo and match its existing describe and naming conventions. Mock only true externals such as network, clock, and filesystem; do not mock the module under test or pure helpers it calls. Cover at minimum each public function, one edge case per conditional (empty input, null, zero, largest allowed value), and thrown errors asserted by type and message. Avoid snapshot tests for logic. Run the suite with coverage, report uncovered lines, and add cases until every branch of the public API is exercised or you explain why a line is unreachable.

Same task in other tools

Questions about this prompt

Should I attach the file or let Cursor find it?

Attach it. Open the module or @ mention it along with its main dependencies, because branch mapping only works when the agent can read every import. Left to search, it sometimes tests a similarly named file, and you get a green suite for the wrong module.

Cursor mocked a pure helper and the tests pass trivially. What now?

That violates the mocking rule in the prompt, so call it out and have the agent use the real helper. Over-mocking is the most common failure on this task; the tell is a test file where nearly every import is replaced and the assertions only check that mocks were called.

How do I use this on a legacy module with zero tests and heavy side effects?

Ask for characterization tests first: capture what the code does today, even where the behavior looks wrong, and mark surprising cases with comments. Refactor for injectability afterward. Splitting it into two explicit steps stops the agent from fixing behavior mid-test-writing and hiding real regressions.

Related prompts