怎么验收 AI 写的代码?How do you accept AI-written code?
AI 一次写出几千行代码,已经没人读得完。逐行审查成了形式,真正要回答的是:它做的事,是不是我要的事?下面是一套不依赖读代码的验收方法:写下你自己的验收标准,真的跑一遍,用证据决定收不收。AI can produce thousands of lines at once and nobody reads them all. Line-by-line review becomes a formality, and the real question is whether what it built is what you wanted. Here is a way to accept work without reading every line: write your own acceptance criteria, run them for real, and decide on evidence.
为什么只看 diff 不够Why reading the diff is not enough
- 代码量超出了人能认真读完的范围,评审容易变成“看着没问题”。The volume is beyond what a person can read carefully, so review drifts into “looks fine”.
- AI 写的测试和实现往往出自同一次推理:理解错了,两边会一起错,测试照样全绿。Tests and implementation written by AI often come from the same reasoning. If it misunderstands the requirement, both are wrong together and the tests still pass.
- “能跑起来”不等于“符合需求”。需求里的细节,只有写成可执行的期望才会被真正核对。“It runs” is not “it meets the requirement”. Details only get checked once they are written as executable expectations.
独立验收的四条原则Four principles of independent acceptance
- 独立于实现。Independent of the implementation.从接口边界和界面外部去验,不依赖被测代码的内部结构,也不由写代码的那一方来定标准。 Check from the API boundary and the UI outside. Do not rely on the code’s internals, and do not let the author set the bar.
- 标准由你定。You own the criteria.期望值来自需求,而不是来自 AI 生成的代码。你说“订单创建后状态是 pending”,用例就这样写。 Expected values come from the requirement, not from generated code. If a new order should be pending, the case says so.
- 要有证据。Keep evidence.请求与响应记录、界面每一步的截图,比一句“我检查过了”可靠,也能转发给别人看。 Recorded requests and responses and a screenshot of every UI step beat “I checked it”, and can be forwarded to others.
- 可重复,并对应版本。Repeatable and tied to a version.同样的用例每次得到同样的结论,并且知道它验的是哪一次提交。 The same case gives the same verdict every time, and you know which commit it verified.
接口验收清单API acceptance checklist
- 状态码之外,断言响应体里的关键字段,不要只看到 200 就算过。Assert the key fields in the response body, not just a 200 status.
- 错误路径:未登录、参数缺失或错误、重复提交,返回的应该是什么。Error paths: not logged in, missing or invalid parameters, duplicate submissions. What should come back?
- 权限:换一个账号,能不能看到不该看到的数据。Permissions: can another account see data it should not?
- 数据副作用:创建之后能查到,删除之后查不到,用流程把几个用例按顺序串起来。Side effects: created records can be fetched, deleted ones cannot. Chain the cases in order as a flow.
- 边界:空列表、分页末页、最大长度、特殊字符。Edges: empty lists, the last page, maximum lengths, special characters.
界面验收清单UI acceptance checklist
- 把关键路径从头走到尾:登录、下单、看到订单。Walk the key path end to end: log in, place an order, see the order.
- 断言用户能看到的结果(标题、文案、数量),而不是某个元素“存在”。Assert what a user can see (headings, text, counts), not that an element merely exists.
- 按人看到的样子找元素:名叫“登录”的按钮、标签是“手机号”的输入框,比 CSS 选择器耐改版。Find elements the way a person sees them: the button named “Log in”, the input labelled “Phone”. This survives redesigns better than CSS selectors.
- 每一步留截图,失败时保存页面、控制台和网络请求,人眼扫一遍就能发现不对。Keep a screenshot of each step, and save the page, console and network requests on failure. A quick look often spots what is wrong.
- Web 和 Android 都要验的话,放进同一个项目里,用同一套方式管理。If you need both Web and Android, keep them in one project and manage them the same way.
用 requestbaby 落地Putting it into practice with requestbaby
requestbaby 把上面的原则做成了工具:用例是 JSON 文件,运行时不调用大模型,结论由你写下的断言决定。最短的一条路径:requestbaby turns these principles into a tool: cases are JSON files, no model is called when running, and the verdict comes from the assertions you wrote. The shortest path:
requestbaby init myapi && cd myapi
requestbaby vars set baseUrl http://localhost:8080 -e dev
requestbaby new case collections/orders 创建订单 -m post
requestbaby send collections/orders/01-创建订单.json --suggest # 看真实响应,按字段写断言
requestbaby run # 跑全部用例
requestbaby verify -e dev --report html # 校验 + 全部用例 + 全部流程,生成报告requestbaby init myapi && cd myapi
requestbaby vars set baseUrl http://localhost:8080 -e dev
requestbaby new case collections/orders create-order -m post
requestbaby send collections/orders/01-create-order.json --suggest # see the real response, assert per field
requestbaby run # run every case
requestbaby verify -e dev --report html # validate + all cases + all flows, write a report
让 AI 帮你写用例时,先让它读 When you want AI to write cases, have it read requestbaby guide(一页写法速查),写完用 (a one-page cheat sheet) first and check the result with requestbaby validate 检查。. The exit code of requestbaby verify 的退出码 0 表示全部通过、1 表示有用例失败、2 表示无法完成验证,可以直接放进 CI。 is 0 when everything passed, 1 when a case failed and 2 when verification could not complete, so it fits straight into CI.
几个常见的坑Common pitfalls
- AI 为了让用例通过而改用例。AI edits the cases to make them pass.把用例文件放进版本库,评审用例的 diff:它比读实现代码轻松得多,断言被放宽一眼就能看出来。 Keep case files in version control and review their diffs. That is far lighter than reading the implementation, and a loosened assertion is easy to spot.
- 断言写得太松。Assertions that are too loose.用 Use
send --suggest看一次真实响应,按字段写断言,而不是只断言状态码。 to look at a real response and assert per field rather than only the status code. - 只测顺利的那条路。Only testing the happy path.错误路径和权限问题,恰恰是 AI 最容易漏的地方。 Error paths and permissions are exactly what AI tends to miss.
- 忽略时过时不过的用例。Ignoring flaky cases.同一个提交上结果不稳定的用例会被标成“不稳定”,先找出原因再信任它的结论。 A case that passes and fails on the same commit is flagged as flaky. Find out why before trusting its verdict.
下一步Next steps
免费下载,几分钟内跑出第一份带截图的验收报告。想先看看它的样子,回到Download it free and get your first screenshot-backed acceptance report within minutes. To see what it looks like, go back to the 首页home page;遇到问题见; for help see the 支持页support page。.
下载 requestbabyDownload requestbaby