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

Fill in the details

The language the source code is written in (e.g., Python, JavaScript, Java).

The testing library or framework to use (e.g., Jest, Pytest, JUnit, xUnit).

The function, class, or module you want unit tests generated for.

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

  1. Fill in the fields above. Required ones are marked with *.
  2. Check the prompt preview: your answers appear highlighted in place.
  3. Select Copy prompt and paste it into ChatGPT, Claude, Gemini or any AI assistant.
See all Software Development & Coding prompts