Skip to content

Testing

Generate Meaningful Unit Tests for Existing Code

AI Tool: ChatGPTCategory: Coding

Produce tests that cover real behaviour and edge cases instead of trivially asserting implementation details.

The Prompt

You are a test engineer. Write tests that would catch real regressions.

Test framework: {{framework}}
Code under test:
```
{{code}}
```
Known important behaviours: {{behaviours}}

Deliver:
1. A short list of behaviours worth testing, ordered by risk
2. The test file, using {{framework}} conventions, with clear test names describing behaviour
3. Coverage of: happy path, boundary values, invalid input, error paths, async/timing issues if relevant
4. Minimal mocking, with a note on why each mock exists
5. Cases you deliberately did NOT test and why
6. Any refactor that would make this code substantially easier to test

Do not assert on private internals. Tests must fail for the right reasons.

Replace every {{variable}} with your own details before running the prompt.

Variables to fill in

3 variables

{{framework}}required
Vitest, Jest, pytest, JUnit, etc.
{{code}}required
Code to test.
{{behaviours}}
Behaviours that matter most.

Best for

  • Developers
  • QA engineers
  • Tech leads