coding template

Write tests for existing code

Covers the cases that actually break, not just the happy path.

Use this template

Opens the composer with the prompt filled in. Free — an emailed code is all you need.

The prompt

Copy it, or use the button above to drop it straight into the composer. Everything in [SQUARE BRACKETS] is a slot you fill in.

Write tests for this code.

```
[PASTE CODE]
```

Test framework: [e.g. pytest, vitest, PHPUnit]
Existing test conventions in my project: [PASTE ONE EXISTING TEST, OR SAY "none yet"]

Cover, in priority order:
1. The behaviour a user depends on (the contract), not the implementation details.
2. Boundary values: empty, one, many, maximum, negative, zero, null/None.
3. Error paths — what should raise, and what should be handled silently.
4. Any concurrency, ordering or state-leak risk you can see.
5. Regression cases for bugs the code's structure suggests it has had.

Rules:
- Match my project's existing test style if I gave you one.
- One assertion concept per test; name tests after the behaviour, not the function.
- No mocking of the thing under test. Mock only what crosses a boundary (network, clock, fs).
- Tell me which cases you deliberately did not test and why.

When to use it

  • You have an error and want the cause, not five things to try
  • You've inherited code and need the model in your head before changing it
  • You want tests for the cases that actually break, not the happy path

Which mode suits it

Code questions want the answer first and an explicit “I can't see that” instead of a confident guess about code that wasn't pasted in.

  • Precise — shorter, fact-first, no padding

More coding templates