Write unit tests for my code
Comprehensive unit tests covering happy paths, edge cases, and failures.
The prompt
Write unit tests for this code.
Language and test framework: [e.g. Python + pytest, TypeScript + Vitest]
Code under test:
[PASTE]
Cover:
- Happy paths for each public function/method.
- Edge cases: empty, null, boundary values, large inputs, unusual types.
- Error handling and exceptions.
- Mock external dependencies (network, database, time, randomness).
Return the test file(s), a coverage map (which behaviors each test covers), and any bugs or untestable design you discovered while writing tests.
Highlighted [brackets] are blanks to replace with your own details.
Fill in the blanks and use this promptMore Software Development prompts
What to fill in
- e.g. Python + pytest, TypeScript + Vitest
- PASTE
How this prompt is built
This prompt follows the RTF structure (Role, Task, Format). RTF tells the model who to be, what to do and what shape the answer should take. It is the quickest structure that still gives noticeably better results than a bare request.
Related prompts
- Convert code to another language or frameworkIdiomatic translation of code between languages or frameworks, with notes on differences.
- Write documentation, a README, or API docsGenerates clear technical documentation from your code or notes.
- Write precise TypeScript types for my data and APIsSafer, readable TypeScript types that rule out impossible states, replace unsafe casts, and come with compile-time tests.
- Write a style guide that documents my app's existing design codeReverse-engineers colors, typography, spacing, and component patterns from your codebase into a STYLE_GUIDE.md developers and AI agents can follow.