Generate Test Cases for a Function
Produce a test plan and test code covering normal cases, edge cases and failure modes.
When to use it: Use when adding tests to existing code or before refactoring it.
Works with: Any chat assistant
What you'll need
- Test Framework (required)
- Code (required)
- Expected behavior / rules (optional)
The prompt
Write tests for this code using [TEST FRAMEWORK]. ``` [CODE] ``` Expected behavior and business rules: [RULES] 1. First list the test cases as a table: Case | Input | Expected result | Why it matters. Cover normal cases, boundaries, invalid input and error handling. 2. Then write the test code. Use descriptive test names and keep each test focused on one behavior. 3. Point out behavior that's ambiguous from the code, where you had to guess the expected result. Don't change the code under test unless I ask.
Words in [BRACKETS] are placeholders. Fill them in below, or replace them yourself after copying.
Customize the prompt
What you'll get
A test-case table, test code and notes on ambiguous behavior.
How to use it
- Fill in the fields above (at least: Test Framework, Code) and select Generate My Customized Prompt.
- Copy the result, or open it directly in ChatGPT, Claude or Gemini.
- Review the answer and ask follow-up questions to refine it.
- Edit the final result in your own words and check any facts before using it.
Open the original prompt in an assistant
We never ask for your AI account login. ChatGPT and Claude open with the prompt filled in when it's short enough for a link; Gemini always needs a paste.
Tips
- Run the generated tests: a test that passes for the wrong reason is worse than no test.
Limitations
- AI-suggested code can be wrong or insecure. Review it and run your tests before relying on it.
Related prompts
- Explain Unfamiliar CodeGet a plain-language walkthrough of what a piece of code does, how data flows through it and what could go wrong.
- Debug an Error SystematicallyWork through a bug with likely causes ranked, checks to confirm each one and a minimal fix.
- Structured Code ReviewReview a change for correctness, security, readability and tests, with comments ranked by severity.
- Review an API DesignGet feedback on endpoint naming, request and response shapes, errors, pagination, versioning and security.