PromptCode reviewOutput shown

Tests for a function, including the odd cases

A short list of cases first, then the tests.

What you get

You should get a plain-words list of cases first (normal, edge and failure), then one test per case with a clear name. The list lets you check the thinking before you read any code. If the function has a bug, the model should point it out and show the test that fails. Run every test yourself: a test that never fails proves nothing.

Example output (illustration of the shape of a result, not a recorded test)

Cases: normal list; empty list; one item; negative price; non-numeric price.
test_empty_list_returns_zero ...
test_negative_price_raises ...

How to use it

  1. Scroll to the end of this page and copy the prompt.
  2. Replace each [bracket] and paste your code or diff at the end of the prompt.
  3. Read the answer as a second opinion. Check each finding against the code before you act on it.

Fill in these fields

Change only the parts in [brackets]. The rest of the wording keeps the answer on task.

FieldWhat to enter
[language]Your own details.
[test framework]Your own details.
[paste the function]Your own details.

Change it for your case

  • If you use a different framework, state it in the first line and give one example test from your project.
  • If the function calls the network, add 'mock the network call'.
  • For a bug fix, ask for 'one regression test that fails before the fix and passes after'.

Tips

  • Run the tests. A generated test that never fails proves nothing.

The prompt

Copy it, then fill in the [brackets]. We have not tested this prompt; we call a prompt tested only when a test result is shown.

Write tests for this [language] function using [test framework].
First list the cases in plain words: normal, edge (empty, zero, very large, wrong type) and failure cases.
Then write one test per case with a clear name. Do not change the function. If the function has a bug, say so and show the failing test.

[paste the function]