Back to guide/Developer Tools

Test Generation with Edge Cases

Generate tests that catch real bugs — with edge cases, error paths, and comments explaining WHY each test matters.

testingdevelopmentchatgpt
Edit View
Prompt
Generate tests for this {{language}} code using {{test_framework}}:

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

Requirements:
- Cover the happy path with realistic data
- Test edge cases: empty input, null/undefined, boundary values, very large input
- Test error paths: invalid input, network failures, permission errors
- Use descriptive test names that explain the expected behavior: "should return empty array when user has no orders"
- Arrange-Act-Assert pattern
- No mocks unless the dependency is external (database, API, filesystem)

For each test, add a brief comment explaining WHY this case matters — what bug would it catch?

Variables to customize

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

Why this prompt works

The 'why this case matters' comment forces ChatGPT to justify each test, filtering out redundant cases. The 'no mocks unless external' rule produces tests that actually test behavior.

Save this prompt to your library

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