Ask the model for tests (not just code)
Goal: Get small tests that prove a fix before you trust the patch—so you are not pasting mystery code into production.
Best for: Beginners who get code dumps with no way to check.
Models love to “helpfully” rewrite half your file. Flip the order: tests first, patch second, and only after you approve the tests. Include at least one check you can run by hand without a framework.
Ask the model for tests that fail on the bug first—then for the fix. Tests-after-the-patch often rubber-stamp the patch.
Keep the failing tests even if you discard the model’s first patch. Tests are the asset; the patch is disposable.
Why beginners skip this
Skipping the hard part of “Ask the model for tests (not just code)” feels fine until a live thread pays the bill. Hold: Failing test first; patch second; you run the proof—date a refuse-line this week, or nothing changed Mid-week cost shows up as rework, not as a missing bookmark.
Step 1 — Tests-first ask
Do this step with a real artifact open—not from memory.
Before any fix:
1) Propose 3 tests (input → expected output)
2) Mark which I can run manually without a framework
3) Wait for my OK
Only after I approve tests, suggest the smallest patch.
Do not refactor unrelated code.
Step 2 — Date-parse bug
Example
Filled prompt
Bug: webhook retries double-charge in staging only.
Demand: failing test that reproduces double-post, then minimal patch.
I run the test before merge. No "trust me" patches.
What good output looks like
- Names files/functions you provided for “Get small tests that prove a fix before you trust ”
- No secrets in logs; no mystery whole-repo rewrite
- Explain-before-patch or minimal repro respected
- Pass/fail: you can restate the change in 3 bullets
Step 3 — You run one test for real
Do not rubber-stamp. Run the manual case. If it fails, paste the failure back—do not ask for a bigger rewrite yet.
Manual test failed: input X expected Y got Z. Adjust the smallest patch only. Do not add new features.
Example
Filled prompt
Review these tests for tautologies (tests that only mirror the new patch lines).
Paste: [tests asserting exact new if-branch text].
Flag which tests prove behavior vs which only echo the patch.
What good output looks like
- No secrets in logs; no mystery whole-repo rewrite
- Explain-before-patch or minimal repro respected
- Pass/fail: you can restate the change in 3 bullets
- Names files/functions you provided for “Get small tests that prove a fix before you trust ”
Save this card
Card: Failing test first; patch second; you run the proof—date a refuse-line this week, or nothing changed. Keep this beside the tool; read before you start.
1. What I shipped: ___ 2. What I refused: ___ 3. What I will never-do again: ___ (date: Asia/Shanghai)
- [ ] Tools/writes paused
- [ ] Refuse-line dated
- [ ] Artifact path saved
- [ ] Next link chosen (or stop)
Before you start
Open the failing test, diff, or ticket for “Get small tests that prove a fix before you.” Keep secrets out of the chat. Have the file path you will name. Guide: code-tests-with-the-model. If you only have a blank practice box, stop and fetch the real job first.
- Goal in one line: ___
- Allowed tools: ___
- Forbidden: ___
- Human approve needed for: ___
How to use this week
This week in code: get one small test that proves a fix before you merge; refuse tests that invent APIs you don’t have on a live artifact—not a blank demo. Write one refuse-line and date the note (Asia/Shanghai). If you only skimmed code-tests-with-the-model, put 25 minutes on the calendar and redo once.
Keep it real
Run this guide’s Practice now on work you will actually ship this week—not a fictional scenario. Dated notes beat perfect theory.
Ship the practice
Close the tab only after Practice now is done on a real artifact.
Do not bookmark-only
Finish Practice now, then tick this guide on your path. Titles unread are not skills.
Close the loop
After Practice now, write one line: what you will refuse next time. That line is the habit.
Example
Filled prompt
Live artifact this week for: Get small tests that prove a fix before you trust the patch—so you are not pasting mystery
Name real files/people. No invented facts; label Unknowns; stop before send/delete.
Return working prompt + one pass/fail check I can mark in a minute.
What good output looks like
- Explain-before-patch or minimal repro respected
- Names files/functions you provided for “Get small tests that prove a fix before you trust ”
- Pass/fail: you can restate the change in 3 bullets
- No secrets in logs; no mystery whole-repo rewrite
Red flag
Merge without tests; tests calling APIs you do not have; model editing tests to match a bad fix—stop.
Pitfalls
| Pitfall | Fix |
|---|---|
| Accepting code before tests | Hard rule: tests → OK → patch |
| Framework-only tests you cannot run yet | Demand one manual case |
| “While we’re here” refactors | Ban unrelated edits |
| Trusting the model’s “all tests pass” | You run them |
Example
Filled prompt
Temptation: skip the habit for code-tests-with-the-model to “save five minutes.”
Job still: Get small tests that prove a fix before you
Do the smallest correct pass: Done visible · one checkable artifact · Unknowns labeled [?].
Boundaries: draft only; no silent send; no invented metrics.
Return: the artifact + the refuse-line you said aloud.
What good output looks like
- Names the shortcut you refused (specific to code-tests-with-the-model)
- Still delivers a checkable artifact for “Get small tests that prove a fix before you”
- Unknowns labeled; draft-only respected
- Pass/fail: refuse-line written and dated (code-tests-with-the-model #4)
Practice now
Live card: one real code change under “Ask the model for tests (not just code)”—diff-only + test note (Asia/Shanghai).
Today: paste one real bug + minimal repro. Demand: (1) failing test sketch (2) then minimal patch. Reject a patch with no test. Run or mentally simulate the test.
Today card (copy) — code-tests-with-the-model: 1. Artifact I will produce: ___ 2. Pass/fail check: ___ 3. Refuse-line if tempted to skip verify/send: ___ (date: Asia/Shanghai) 4. One never-do from this guide: ___
- [ ] Artifact path written
- [ ] Refuse example would say "yes"
- [ ] Dated Asia/Shanghai
One sentence takeaway
Failing test first; patch second; you run the proof—date a refuse-line this week, or nothing changed
- You can point to a dated refuse-line
- You have one artifact path from tonight
- You can teach the red flag in one sentence
Next
Explain then change · PR description · Minimal repro · Code path · Coding agent boundaries
Pair with today: open the first Next link (code-explain-then-change) only after you dated a refuse-line for this guide (Asia/Shanghai).
向模型要测试(不要只要代码)
目标: 先拿到能证明修复的小测试,再信任补丁——避免把神秘代码贴进生产。
适合: 经常拿到大段代码却无法验证的新手。
模型很爱「好心」重写半个文件。把顺序翻过来:先测试,再补丁,而且只有你批准测试之后。至少包含一个不用测试框架也能手跑的检查。
先让模型写出在 bug 上会失败的测试——再要修复。补丁后再写的测试,常常只是给补丁盖章。
即使丢掉模型第一版补丁,也留下失败测试。测试是资产;补丁可丢。
为什么新手跳过
「先修」却没有证明测试,回归明天回来。先写能证明修复的小测试再信任补丁,更便宜。
步骤 1——测试优先提问
用真实材料做这一步——不要凭记忆。
在任何修复之前:
1)提出 3 个测试(输入 → 期望输出)
2)标出哪些我可以不用框架手跑
3)等我 OK
只有我批准测试后,再给最小补丁。
不要重构无关代码。
步骤 2——日期解析 bug
实例
填好的提示词
Bug:午夜 UTC 时 session refresh 失败。
要求:(1) 失败测试草稿,命名 test_session_refresh_midnight;(2) 再给最小补丁。
合并前我自己跑测试;没有测试就拒补丁。
像样的输出大概长这样
- 3 个失败测试
- 补丁前
- 无多余模块
- 贴合填例里的约束
- 不编造事实、负责人或指标
- 新手能看懂;可直接交给同事
步骤 3——你真的跑一个测试
不要盖橡皮图章。跑手测。若失败,把失败贴回去——先别要更大重写。
手测失败:输入 X 期望 Y 得到 Z。只调最小补丁。不要加新功能。
实例
填好的提示词
补丁自称「已修好」,但没有测试。
先写时区边界的失败测试,我来跑。
像样的输出大概长这样
- 标出套套逻辑
- 具体
- 新手能懂
- 贴合填例里的约束
- 不编造事实、负责人或指标
保存这张卡
卡面:小测试证明修复 → 全绿 → 再合。合入前看卡;缺项就停,不硬开。
1. 我交出了:___ 2. 我拒绝了:___ 3. 我永不再做:___(日期:Asia/Shanghai)
- [ ] 工具/写入已暂停
- [ ] 拒做句已标注日期
- [ ] 成品路径已存
- [ ] 已选下一步(或停)
开始前
打开你真正会用的账号/项目。准备好与「向模型要测试(不要只要代码)」相关的真实材料(不要空白练习框)。
默认姿态:在人确认发送/写入之前只出草稿。授予新工具前,先写一条带日期的拒做句(Asia/Shanghai)。
- 一句话目标:___
- 允许的工具:___
- 禁止:___
- 需要人批准:___
本周怎么用
本周一次真实修复:先让模型写出能证明修复的小测试,全绿再合并。拒绝发明你仓库里没有的测试 API。过/不过注明日期(Asia/Shanghai)。
保持真实
用本周真会交付的工作做「现在就练一次」——不要虚构场景。带日期的笔记胜过完美理论。
把练习做完
实卡:「向模型要测试(不要只要代码)」下一次真实改代码——只要 diff + 测试备注(Asia/Shanghai)。
今天把「向模型要测试(不要只要代码)」练完:真实材料、过/不过、一句永不做。注明日期(Asia/Shanghai)。
不要只收藏
做完「现在就练一次」,再在路径上打勾。没练过的标题不是技能。
闭环
「现在就练一次」后写一行:下次你要拒绝什么。那一行才是习惯。
红旗
无测试就合主分支;测试调用了不存在的助手函数却当绿。模型改测试去迁就坏实现——立刻停。卡上写不清就不继续——先补检查项再跑。
常见坑
| 坑 | 改法 |
|---|---|
| 先收代码再谈测试 | 硬规则:测试 → OK → 补丁 |
| 只有你暂时跑不了的框架测试 | 要求一个手跑用例 |
| 「顺便」重构 | 禁止无关编辑 |
| 相信模型说「测试全过」 | 你来跑 |
实例
填好的提示词
任务:Get small tests that prove a fix
场景要点:缺陷单/diff 打开;练习编号 3/4。
边界:仅草稿;未知 [?];禁止悄悄发送;禁止编造指标。
返回:可检查产出 + 过/不过理由一行。
像样的输出大概长这样
- 约束贴着「向模型要测试(不要只要代码)」与 code-tests-with-the-model
- 未知标 [?];不编造负责人/数字
- 不可逆动作前停下
- 一分钟内能打过/不过(code-tests-with-the-model #3)
实例
填好的提示词
任务:Get small tests that prove a fix
场景要点:缺陷单/diff 打开;练习编号 4/4。
边界:仅草稿;未知 [?];禁止悄悄发送;禁止编造指标。
返回:可检查产出 + 过/不过理由一行。
像样的输出大概长这样
- 约束贴着「向模型要测试(不要只要代码)」与 code-tests-with-the-model
- 未知标 [?];不编造负责人/数字
- 不可逆动作前停下
- 一分钟内能打过/不过(code-tests-with-the-model #4)
- [ ] 成品路径已写
- [ ] 拒做例句会说「可以」
- [ ] 已标注 Asia/Shanghai 日期
- 能指出一条带日期的拒做句
- 今晚有一条成品路径
- 能用一句话说清红旗
← Back to home · Learn · Tools · Compare · Start