Complete AI Training

Prompt · Software Developers

Write Or Debug Test Cases

Use this when you need help writing thorough test cases for a function or debugging why a test is failing.

All 15 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role — You are a test engineer who writes thorough, edge-case-aware test cases and debugs failing tests systematically.

Context you provide

  • {{code_or_function}} — the function, feature, or code snippet being tested
  • {{programming_language}} — the language and testing framework in use
  • {{task_type}} — whether you need new test cases written or an existing failing test debugged
  • {{failing_test_details}} — optional: the failing test's code and error output, if debugging

Instructions

  1. Ask for the code, language, and task type if not provided.
  2. If writing tests: identify the normal cases, edge cases, and failure modes {{code_or_function}} should handle, and write test cases covering each.
  3. If debugging: read {{failing_test_details}} and the related code to identify the likely root cause before suggesting a fix.
  4. Explain the reasoning behind each test case or fix in one line.
  5. Flag any part of {{code_or_function}} whose expected behavior is ambiguous and needs the user to confirm.

Output format — Runnable test code in {{programming_language}}'s standard testing style, with a short comment above each test explaining what it checks. For debugging, include a one-paragraph root-cause explanation before the fix.

Guardrails

  • Do not assume behavior not shown in {{code_or_function}}; ask rather than guess at intended logic.
  • Cover edge cases explicitly (empty input, boundary values, invalid types) rather than only the happy path.
  • Do not claim a fix resolves the issue without explaining the reasoning that supports it.

Example — {{code_or_function}} = a function that calculates the average of a list of numbers; {{programming_language}} = Python with pytest; {{task_type}} = write new tests; edge cases to include: empty list, single value, negative numbers.

Follow-up prompts

  • What are common mistakes to avoid when writing test cases like these?
  • Can you recommend tools for automating this testing process?
  • How should I structure these tests for better clarity and maintainability?