Generate Unit Tests
Generate a comprehensive, production-ready unit test suite for the provided code snippet.
- Category
- Software Development & Coding
- Output
- Code
- Fields
- 3
- software-development
- testing
- code-review
- best-practices
- debugging
Prompt
You are an expert software engineer specializing in test-driven development and quality assurance. Your task is to generate a comprehensive, production-ready unit test suite for the provided code snippet.
**Context & Inputs:**
- Programming Language: Programming Language
- Test Framework: Test Framework
- Source Code:
```
Source Code
```
**Instructions:**
1. Analyze the source code to identify its core logic, expected inputs/outputs, and potential side effects.
2. Write a complete test file using the specified language and framework, strictly adhering to their official conventions and community best practices.
3. Ensure the test suite explicitly covers these four scenarios:
- Happy Path: Verify standard, expected behavior with valid inputs.
- Edge Cases: Test boundary conditions, empty inputs, null/undefined values, and extreme limits.
- Error Handling: Confirm that the code correctly raises, catches, or propagates expected exceptions or errors.
- External Dependencies: Mock any external calls (APIs, databases, file systems, third-party libraries) to ensure tests run in isolation.
4. Add a clear, concise comment above each test function explaining its specific goal or scenario.
5. Rely exclusively on the provided code and stated framework. If any behavior, dependency, or error type is ambiguous or undocumented, list them under an "Open questions" section before generating the code. Do not invent dependencies, return types, or error behaviors.
**Output Requirements:**
Return only the raw test code. Do not wrap it in markdown code fences, and do not include any introductory, explanatory, or concluding text. Ensure the code is directly copy-paste ready and syntactically correct.
How to use this prompt
- Fill in the fields above. Required ones are marked with *.
- Check the prompt preview: your answers appear highlighted in place.
- Select Copy prompt and paste it into ChatGPT, Claude, Gemini or any AI assistant.
More Software Development & Coding prompts
- Bug Fix Brief for an AI AgentConvert raw bug reports into precise, unambiguous execution briefs tailored for AI coding agents.
- Caching Strategy DesignerDesign a robust, production-ready caching strategy for the specified feature, endpoint, or data flow.
- Database Schema Designer NormalizedProduce a production-ready, normalized relational schema with precise constraints, justified indexes, and practical migration guidance.
- Production Error Log TriageROLE: You are a senior on-call SRE and incident response engineer specializing in production debugging.
- Bug Diagnosis and FixYou are an expert software engineer and debugging specialist.
- Conventional Commit Message WriterROLE: You are a senior software engineer and version control specialist dedicated to maintaining clean, standardized, and highly readable Git history.