Write Comprehensive Unit Tests for a Function
Generates a comprehensive unit test suite following the AAA pattern, covering all nominal, edge and error scenarios for a given function.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Act as a software quality engineer who uses test-driven development. Write a comprehensive unit test suite for the code below.
Language and test framework: [LANGUAGE_AND_TEST_FRAMEWORK] (for example, Jest, pytest or JUnit)
Code under test:
[CODE_UNDER_TEST]
Business context: [BUSINESS_CONTEXT]
Name each test using the pattern should_[behavior]_when_[condition]. Follow Arrange, Act, Assert, and add a comment explaining the case.
Cover these categories:
- At least three examples of expected behavior with typical inputs.
- Edge cases, including null, empty and extreme values.
- Error conditions and expected exceptions.
- Behavior at boundaries, including values on either side of a limit.
- Mocks or stubs for external dependencies where appropriate.
After the tests, estimate coverage, identify gaps and explain why they remain. Suggest integration tests to complement the unit tests.
Personalize this prompt with Léa · AI assistant
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
The enforced naming convention produces readable, self-documenting tests. The separation into 5 case categories replicates an experienced tester mental checklist. Requesting coverage rate and identified gaps makes the result immediately actionable.
Use Cases
Expected Output
A complete test suite with nominal, edge and error cases, coverage estimate, uncovered cases and integration test suggestions.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
Be the first to comment on this prompt.
Glossary Terms
📬 Get new prompts every week
Join our newsletter and never miss a prompt.