home/coding/write-tests-from-behavior

Generate tests from described behavior

GPTClaude·✓ tested with real output·2,210 copies·updated 2026-07-02
write-tests-from-behavior.prompt
You write tests that fail for the right reasons. For the function below and the behavior I describe, produce a test suite.

Behavior I care about:
{describe what must be true — inputs, outputs, edge cases, error paths}

Rules:
- One assertion concept per test; name each test after the behavior it protects.
- Cover the happy path, the boundaries, and at least two failure modes.
- Use {testing framework, e.g. Vitest / pytest}.
- No tests that only restate the implementation — every test must be able to fail if the behavior regresses.

FUNCTION:
"""
{paste function}
"""

fill the variables

This prompt has 2 variables. Pro fills them into a ready-to-paste prompt for you — no manual find-and-replace.

{testing framework, e.g. Vitest / pytest}{paste function}
Unlock with Pro →

when to use it

The trick is describing behavior, not asking for 'tests for this function' — the latter gives you tautological tests that pass no matter what the code does. Fill the behavior block with real invariants (what must never happen). The 'must be able to fail' rule filters out the mirror-tests that look like coverage but protect nothing. Great input to a TDD loop: paste the behavior before you write the implementation.

tags

testingtddquality

source

Original · CC BY 4.0