wowprompt

Unit tests for a pasted function with edge cases

Writes a full unit test file for one function, covering normal cases, edge cases and errors, in your test framework. Use it to add coverage to existing code or to lock behaviour before a refactor.

A test case plan table followed by a complete, runnable test file with clearly named tests grouped by behaviour
The output this prompt produced, unedited.

The prompt

Fill in these first

  • Language: [e.g. TypeScript, Python, Java, PHP]
  • Test framework: [e.g. Jest, Vitest, pytest, JUnit, PHPUnit]
  • Function to test: [paste the function here]
  • Dependencies it calls: [database, API, clock, file system, or none]
  • Known business rules: [rules the function must follow]

Task

Write unit tests that would catch a real regression in this function, not only confirm the happy path.

Output format

  1. Test plan table:

| # | Behaviour tested | Input | Expected result | Type (normal, edge, error) |

Include at least four normal cases, four edge cases and two error cases.

  1. The complete test file, ready to run, with imports and any mocks or fixtures.
  2. Notes: anything in the function that is hard to test, and one small change that would make it easier.

Edge cases to consider

  • Empty, null or missing values
  • Zero, negative and very large numbers
  • Boundary values at and around each limit
  • Unusual strings: whitespace, Unicode, very long input
  • Duplicate entries and unsorted input
  • Time zones and date boundaries where dates are involved

Quality rules

  • Test names describe the behaviour, e.g. returns zero when the cart is empty.
  • One behaviour per test, arranged as setup, action, assertion.
  • Mock external dependencies; never call real networks or databases.
  • Freeze the clock for any time-based logic.
  • Do not change the function under test.
  • If a case reveals a likely bug, write the test for correct behaviour and flag it in the notes.
unit test generatorwrite unit testspytest examplesjest unit teststest edge cases

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity