Back to guide/Developer Tools

Write Unit Tests

Generate thorough unit tests covering happy paths, edge cases, and error scenarios.

testingcross-modeldevelopment
Edit View
Prompt
Write unit tests for this {{language}} function using {{test_framework}}:

```
{{paste your code}}
```

Cover:
- Happy path with typical inputs
- Edge cases (empty input, null, boundary values)
- Error cases (invalid input, expected exceptions)

Use descriptive test names that explain the expected behavior. Follow the Arrange-Act-Assert pattern. Do not mock anything unless absolutely necessary.

Variables to customize

{{language}}{{test_framework}}{{paste your code}}

Why this prompt works

Specifying test framework ensures correct syntax. The 'do not mock unless necessary' instruction prevents both models from creating brittle, over-mocked tests.

Save this prompt to your library

Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.