Edge Case & Test Case Generator
Analyzes a function or feature and generates a comprehensive list of edge cases and corresponding test cases, catching scenarios developers commonly miss.
Developers writing or reviewing functions who want thorough test coverage without manually brainstorming every edge case, especially before shipping code to production.
You are a QA-minded senior engineer known for thinking of edge cases other developers miss.
Language/framework: {{language_framework}}
Code/function to test:
{{code_block}}
Expected normal behavior: {{expected_behavior}}
Do the following:
1. List the standard/happy-path test cases first (2-3 cases covering typical expected use).
2. List edge cases across these categories: boundary values (empty, zero, max/min, single item), invalid/malformed input, unexpected types or null/undefined values, concurrency or timing issues (if relevant), and unusual but valid real-world scenarios that are easy to overlook.
3. For each edge case, state what the code should do (the expected correct behavior) and flag if the current code as written would likely fail that case.
4. Write actual test code for the 5 most important edge cases identified, using an appropriate testing framework for the language ({{testing_framework_if_known}}).How to use
- Paste the function or code block along with a description of its expected normal behavior.
- Specify your testing framework so generated test code is directly usable.
- Review flagged cases where the current code would likely fail and fix them before considering the code production-ready.
- Add the generated test code to your test suite, adapting variable names and imports to match your project structure.
Example input
Language: JavaScript. Code: [a function that calculates a discount price given a base price and a discount percentage]. Expected behavior: Returns the discounted price rounded to 2 decimal places. Testing framework: Jest.
Example output
Happy-path cases like a 20% discount on $100, edge cases including a 0% discount, a 100% discount, a negative price input (flagged as likely to fail since the current code doesn't validate for negative values), a discount percentage over 100 (flagged as producing a negative price incorrectly), and floating-point rounding edge cases, followed by 5 Jest test blocks covering the most critical of these scenarios with assertions.
Customization tips
- — For functions handling user input directly, ask for extra emphasis on malicious or malformed input cases.
- — For async functions, explicitly ask for edge cases around timing, race conditions, and promise rejection handling.
- — If you only need the edge case list without full test code, say so to get a faster, lighter-weight response.
Tags
FAQ
What is this prompt for?
How should I customize it?
Are there any limitations?
How is it different from a basic prompt?
Related Prompts
All Coding & Debugging prompts →Code Review Simulator
Simulates a thorough senior engineer code review, flagging bugs, edge cases, readability issues, and security concerns with specific, actionable comments.
Legacy Code Explainer & Refactor Planner
Explains what an unfamiliar or legacy piece of code actually does, then proposes a safe, incremental refactor plan instead of a risky full rewrite.
Root Cause Bug Investigator
Guides a systematic investigation of a bug from symptom to root cause, avoiding quick patches that mask the real problem, and produces a targeted fix.
Related Skills
QA Test Case Generator
Generates a structured set of test cases — happy path, edge cases, and negative tests — from a feature description or user story.
Test Framework Auto-Detector & Generator
Detects which test framework a project already uses (Jest, Vitest, Pytest, Go testing, and more) and writes new tests in that project's existing style, not a generic template.
Code Review & Refactor Assistant
Reviews a pasted code snippet for bugs, readability, and performance issues, then delivers a prioritized refactor with explanations for each change.
Related Articles
How to Test AI-Generated Code Before You Trust It
Learn how to review and test AI-generated code before using it in production, including functionality, security, edge cases, permissions, and regression checks.