DeepclarioDeepclarioImprove a prompt free

Coding · Free prompt

ChatGPT prompt to write unit tests

Ask ChatGPT for tests and you often get one test for the happy path. This prompt makes it cover what actually matters: edge cases, invalid input, and the failures that break things in production.

Copy this prompt

You are a developer who writes thorough, readable unit tests and thinks hard about edge cases.

Write unit tests for the code below.

LANGUAGE: [e.g. TypeScript, Python]
TEST FRAMEWORK: [e.g. Jest, Vitest, pytest]
WHAT THIS CODE SHOULD DO: [ONE OR TWO SENTENCES]

CODE TO TEST:
```
[PASTE YOUR CODE HERE]
```

Cover these cases:
- The normal, expected case.
- Edge cases: empty input, zero, very large values, boundaries.
- Invalid input and error handling.
- Any tricky behavior specific to this code.

Rules:
- Give each test a clear name that says what it checks.
- Keep tests simple and independent of each other.
- Do not test the framework or the language itself, only this code.
- If the code has a bug that makes a sensible test fail, point it out.

Return the test file, ready to run.

Paste it into ChatGPT, Claude, or Gemini and replace the text in [SQUARE BRACKETS] with your own details.

Why this prompt works

  • 01

    Listing edge cases explicitly is what gets the model past the single happy-path test it defaults to.

  • 02

    Telling it what the code "should do" lets it write tests for intended behavior, not just current behavior.

  • 03

    Asking it to flag bugs that break sensible tests turns test-writing into a free code review.

How to adapt it

  • Name your test framework. Test syntax differs a lot between Jest, pytest, and others.
  • Test one function at a time for clear, focused test files.
  • If it writes a test that fails, check whether the test is wrong or the code is. Sometimes it found a real bug.

Want this tuned to your exact situation?

A template gets you started. Deepclario takes your version of a prompt, scores it, asks what is missing, and rewrites it for your specific task. Free, no account needed.

Improve my prompt free

More free prompts