Generate comprehensive unit tests with edge cases, mocks, and proper assertions.
You are a testing expert. Generate comprehensive unit tests for the provided code.
## Code to Test
```[language]
[Paste your code here]
```
## Testing Framework
[Jest / Vitest / Pytest / Go testing / etc.]
## Test Requirements
### Coverage Goals
- Happy path scenarios
- Edge cases (empty inputs, boundary values, null/undefined)
- Error cases and exception handling
- Async behavior (if applicable)
### Test Structure
Use the Arrange-Act-Assert (AAA) pattern:
```
// Arrange - Set up test data and mocks
// Act - Execute the code under test
// Assert - Verify the results
```
### Mocking
- Mock external dependencies
- Mock database calls
- Mock API requests
- Reset mocks between tests
## Output Format
```[language]
describe('FunctionName', () => {
it('should [expected behavior] when [condition]', () => {
// Test implementation
});
});
```
## Additional Requirements
- Use descriptive test names
- Group related tests logically
- Include setup/teardown if needed
- Add comments for complex test scenarios
- Aim for 80%+ code coverageThis coding prompt is designed to help you get better results from AI assistants like ChatGPT, Claude, and Gemini. Here's how to make the most of it:
💡 Pro tip: Save this prompt to your collection to use it again later. Well-crafted prompts can save hours of back-and-forth with AI.
Adjust the prompt to match your specific industry, audience, or use case. Adding relevant context improves output quality.
Specify your desired output length (e.g., "in 200 words" or "in 3 bullet points") to get more targeted responses.
Add tone instructions like "professional," "casual," or "technical" to match your brand voice.
Include an example of the output format you want to help the AI understand your expectations.
This prompt has been tested and optimized for all major AI models. For best results with coding-related prompts, consider using an AI-powered IDE like Cursor or Windsurf.
Learn more about using prompts effectively with our comprehensive guides:
0 people found this prompt helpful
Based on 289 reviews
Be the first to share your experience with this prompt!
IDEs
Models
This prompt was reviewed and verified to work with current AI models.
Tested with ChatGPT, Claude & Gemini. Reviewed by 2400+ users.
AI prompts work best when you customize them for your specific situation. Follow these steps to get the most out of Unit Test Generator.