Write the Test That Fails First
Added 2026-11-02
Make it fail first, then implement, so the test proves the intended behaviour.
I am fixing a bug or adding a small feature (described below). Do: 1) write a test that fails right now, with its assertion; 2) confirm it fails for the bug itself, not for environment reasons; 3) list which boundaries it covers and which it misses; 4) suggest the minimal implementation direction; 5) explain how to confirm it turns green without breaking other tests. Do not give the implementation first.
Site original
Chinese original
How to use
先写失败的测试,能避免「测了个寂寞」。
Try tweaking it
- Have it restate requirements and constraints before writing code.
- Ask for the smallest change plus a rollback path, not a full-file rewrite.
What you should get
- A minimal, runnable change with copy-ready code
- Impact list: which files and call sites must follow
Common mistakes
- Asking it to touch ten files at once, then losing track of what broke what.
- Pasting only the error, with no code or version, and getting an unfixable answer.
How to check the output
- The change runs, can be rolled back, and touches nothing unrelated.
- Edge cases (empty, oversized, concurrent) are covered or explained.
Where it works
- Good for: having it restate requirements and constraints, then propose the smallest runnable change.
- Watch out: include versions and a minimal reproduction with the error, or the fix may look plausible but not fit.