Write Unit Tests
Generate thorough unit tests covering happy paths, edge cases, and error scenarios.
testingcross-modeldevelopment
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.
Related prompts
Code Review Assistant
Get thorough code reviews with actionable feedback tailored to your language, framework, and standards.
Code Review with Specific CriteriaGet focused code review feedback with numbered criteria that works on both ChatGPT and Claude.
Explain Complex CodeGet a clear, leveled explanation of any code snippet — calibrated to your experience level.
Debug with ContextSystematic debugging prompt that includes context, error details, and what you've already tried.