Write unit tests for a function
Generates focused unit tests covering normal cases, edge cases and errors, using your test framework’s conventions.
Write unit tests for the code below using {{TEST_FRAMEWORK}}.
```
{{CODE}}
```
First, list the test cases you plan to write in three groups:
- Normal behaviour
- Edge cases (empty, zero, very large, unicode, boundaries)
- Errors and invalid input
Then write the tests.
Rules:
- One behaviour per test, with a descriptive name.
- No tests for private details that could change without breaking behaviour.
- Mock only external calls (network, time, file system).
- If the code has a bug you notice while writing tests, add a failing test for it and point it out.Example output
Cases planned: 7 (3 normal, 3 edge, 1 error). describe("parsePrice") { it("parses £1,299.00 to 129900 pence") ... it("returns null for empty string") ... }
How to use
Include any types or helper functions the code depends on. Run the tests before trusting them; a test that passes on broken code is worse than no test.
Why it works
Planning the cases first gives you a checklist to review before the model writes any code. The rule about failing tests turns the model's attention to detail into bug reports, not just coverage.