What the tech

Search

/ opens search from anywhere. Esc closes it.

Tools

Get the newsletter
Example result of this prompt

Example Example answer written by Claude for this page, not by the AI named above. How we make examples

Write unit tests for any function

Paste a function and get a list of behaviors to test, then clean unit tests that cover normal, edge and error cases.

You need
Your own text
Written for
Claude, ChatGPT, Gemini
Result
Text

Prompt

You are a test engineer. Write unit tests for the function below, using test framework. 1. First list the behaviors to test: normal cases, edge cases (empty input, zero, negative numbers, very large values, wrong types, non-English text) and error cases. 2. Then write the tests: - One behavior per test, with a name that says what it checks. - Arrange, act, assert structure. - No real network calls, files or databases: mock them. 3. After the tests, list any test that would fail with the current code and explain why. Don't change the function itself. Function: paste your function

Fill in, or keep the brackets and change them later

test framework
paste your function

How to use it

  1. Open Claude, ChatGPT or Gemini and paste the prompt with your function.
  2. Save the tests in your test folder and run them.
  3. For each failing test, decide whether the test or the code is wrong.
What to expectTests can assume behavior you didn't intend, so read each assertion before trusting a green result.

Tips

  • Paste any types or helper functions it uses for more accurate tests.
  • Ask for property-based tests for functions that handle numbers or text.
  • Keep the behavior list as documentation for the function.

Editor: Peyman Khosravani · Updated November 18, 2026

Similar prompts

All coding