Skip to content

DirectoryPrompts

Claude Opus 5.5

Write Unit Tests – Unit test prompt for ChatGPT, Claude and Copilot

Freewith a Recaply account
  • Free with an account
  • Copy filled in or download
  • Updates included
votes views

Claude Opus 5.5

This prompt writes unit tests for your code. Paste what the code should do, your test framework and the code; you get a test plan, a runnable test file and the bugs the tests expose.

What you get

  • A test plan table: each case, its input, the expected result and why it matters
  • One complete test file in your framework, ready to run
  • Suspected bugs: the tests that fail because the code disagrees with the intended behavior
  • What the tests leave out, and how to cover it

How to use it

  1. 1
    Describe the intended behavior

    Write what the code should do, with a worked example, not only the code. Tests written from the code alone copy its bugs.

  2. 2
    Run the test file

    Save the file at the path on its first line and run it. Expect the tests listed under Suspected bugs to fail.

  3. 3
    Decide what is wrong

    For each failing test, decide whether the code or the expectation is wrong, fix that one, and run the tests again.

Better results

  • Include a worked example in the expected behavior, such as "a plan started on the 21st of a 30-day month costs a third". One concrete case pins down rounding and boundaries better than a paragraph.
  • Paste one existing test from your repository, so the new file matches your fixtures, naming and imports.
  • Follow up with: "Which of these tests would still pass if the function returned a constant?" It shows you the weak tests.

Questions

How do I get Claude to write unit tests?

Give Claude the code, a plain description of what it should do and your test framework, and ask it to test the intended behavior rather than the current code. Then run the tests. Any that fail point to a bug or to an expectation you need to settle.

What is a good GitHub Copilot prompt for unit tests?

A good GitHub Copilot prompt for unit tests names the framework, describes what the code should do and asks for boundaries and error paths, not only the happy path. This prompt runs as is in Copilot Chat: paste the function and fill in the other two parts.

Can AI write test cases?

Yes, AI writes solid test cases when it knows what the code should do: normal cases, boundaries, invalid input and error paths. Give it the intended behavior and not only the code, or it writes tests that confirm whatever the code does, bugs included.

Updated 6 Oct 2026

Reviews

No reviews yet
Reviews open soonThey will come only from signed-in people who used this prompt.

Similar prompts

More coding prompts

Image prompts

Video prompts

Trending prompts

Newest prompts

Browse all prompts