AI prompts for Developers

Prompt to write unit tests for a function

Writes tests covering the normal case, edge cases, and expected errors, using your test framework.

When to use it When you write a new function, or before changing an old untested one.

The prompt, ready to copy

Role: software quality engineer.
Task: write unit tests for the code below.
Context:
- Language and test framework: [e.g. Jest, pytest, JUnit]
- Expected behaviour in my words: [description]
- Dependencies to mock: [database, API, time, or "none"]
Code:
<source>
[Paste the function or class. Remove any keys or real data]
</source>
Constraints:
- Test the described behaviour, not internal implementation details
- If the code contradicts the behaviour I described, do not pick one; flag the conflict
- Use clear, fake test data
- Do not use framework features you are unsure exist in the stated version
Output:
1. Cases covered: case | input | expected
2. The full test file
3. Cases not tested and why

Example of filled brackets

Language: TypeScript with Vitest
Behaviour: a function that converts Eastern Arabic digits to Western digits and leaves other characters alone
Mocks: none

Check these before you use it

  • Run the tests and confirm they fail when you break the function on purpose
  • Resolve any flagged conflicts before accepting a behaviour

How to use this prompt

  1. Copy the prompt: Press the copy button or select the whole text.
  2. Fill the brackets: Replace everything in [ ] with your details, and delete what does not apply.
  3. Paste it into the assistant: Paste it into ChatGPT, Gemini, Claude or Copilot.
  4. Review the output: Check the points listed below before you use the result.

All Developers prompts