Skip to content

本页由 AI 根据韩语原文翻译,可能存在错误。

第5章 检查与测试——给它检查装置,拿回证据 ​

必读 想跟着这个阶段学下去,一定要读这一章。

一句话总结:AI 在事情看起来做完了的时候就会停下。如果给它一个能告诉它是不是真的做完了的检查装置,AI 就会自己转起"修改后再检查"的循环。 并且,不要听"全部通过了"这句话,要拿到证据(运行过的命令和它的输出,或者画面)。

本章依据 2026 年 11 月 1 日确认过的 Claude Code 和 GitHub 官方文档写成。在第3阶段,我们养成了把结果和原始笔记对照的习惯,到了第4阶段,它被自动化,名字叫"检查装置"。

为什么需要检查装置 ​

官方最佳实践文档是这样说的。Claude 在事情看起来做完了时就会停下。如果没有东西能告诉它是不是真的做完了,"看起来做完了"就是它判断的全部。[1] 这样一来,最后就变成我来当测试,错误会一直留在那里,直到我碰巧发现。[2]

反过来,如果给它能用通过/失败来回答的东西,Claude 就会自己把循环闭合。改动、运行检查,坏了就读输出、修改、再运行。[3]

没有检查装置给了检查装置
"做完了" → 我打开看,找出错的地方检查失败 → Claude 修改 → 再检查 → 通过

来源:本指南的整理(依据是官方文档)[3:1]

理解检查

给它检查装置(以通过/失败作答的检查)后,会有什么不同?

检查装置的种类 ​

检查装置可以是任何 Claude 能读到结果的东西。官方文档举了这些例子。[4]

  • 测试文件:像"5 条待办事项都显示出来了吗?"这样,写下要检查的内容的检查文件
  • 构建是否成功:第4章看到的准备过程(构建)有没有无错误地完成
  • 语法检查器(linter):像代码拼写检查器一样的工具
  • 对比输出的脚本:把结果和事先准备好的正确答案对照的小程序(脚本)
  • 浏览器画面:和设计稿放在一起比较的实际画面

待办看板是不需要构建的网页,所以先从测试文件和浏览器画面用起就行。

如果有这样的装置,文档甚至说,CLAUDE.md 里最有用的一行就是运行它的命令。[5]

最简单的方法是写在请求里。不需要任何设置,今天就能用。[6]

修改待办看板之后,请逐条检查 SPEC.md 里的检查标准,一直做到全部通过为止。

在桌面应用里,Claude 可以启动开发服务器(只在我电脑上把做好的网页预先打开看看的小程序),并在应用里的浏览器窗口里打开,确认自己的改动。默认每次编辑后都会自动检查。[7] 对作为网页的待办看板来说,这是很合适的装置。

请它做测试时,要具体说明要检查什么行为。[8]

不太好的请求更好的请求
做个测试做一个测试,检查会议纪要里的 5 件待办是否都显示在屏幕上,期限是否是日期格式

来源:本指南的例子(要点来自官方文档)[8:1]

理解检查

如果已经有检查装置,官方文档说 CLAUDE.md 里最有用的一行是什么?

拿到证据 ​

不管用什么装置,都要它给证据。就是运行过的命令和它的输出,或者画面。[9] 光是"全部通过了"这句话,几乎得不到任何信息,读输出比自己重新跑一遍更快。[9:1]

把刚才运行的检查命令和它的输出原样给我看。也告诉我通过几个、失败几个。

也要确认检查是不是真的在检查。 故意弄错的时候不会失败的检查,不是装置而是摆设。比如,删掉一件待办再运行,看检查会不会失败。

理解检查

Claude 说“测试全都通过了”。这份指南建议怎么应对?

每次上传时自动检查——GitHub Actions ​

可以让检查不必每次都由人来下令。GitHub Actions 是 GitHub 上自动运行构建、测试、发布的功能。可以让它在每次上传改动时运行测试。[10]

在公开仓库里,可以免费使用 GitHub 提供的标准运行器(替你运行检查的 GitHub 的电脑)。[11]

不需要一开始就配齐所有自动化。 一开始,只用上面的"写在请求里"和浏览器检查就足够了。以后想用的时候,设置文件(写下什么时候运行什么的文件)让 Claude 帮你做就行。

再多了解一点(点击展开)
  • 要做什么,由放在仓库 .github/workflows 文件夹里的 YAML 文件(设置文件)决定。[12]
  • 经常提交、经常检查的习惯叫做持续集成(CI)。它能帮你更早发现错误。[13]
  • GitHub 会把检查结果显示在 PR 界面里。PR 是请求合并分支改动的提议,第6章会讲。可以马上看到我分支里的改动有没有引入错误。[13:1]

理解检查

关于 GitHub Actions,哪种说法是对的?

亲手试一试 ​

  1. 在第4章的 first-board 分支上,让它做一个检查 SPEC.md 里检查标准的装置。
  2. 运行检查,并要它把运行的命令和输出原样给你看。
  3. 故意删掉一件待办再运行一次,看检查会不会失败。确认之后再恢复。
  4. 在应用的浏览器窗口里打开待办看板,亲自数一数待办的数量。
  5. 把检查命令用一行写进 CLAUDE.md。

连续任务:第6章会把到目前为止的改动以 PR 的方式提交,并接受审查。

小结 ​

  • AI 看起来做完了就会停下。给它一个用通过/失败来回答的检查装置,它就会自己修改并再次检查。
  • 检查装置可以是测试、构建、对比脚本、浏览器画面等任何 Claude 能读到结果的东西。
  • 不要听"全部通过了",而要拿到命令和输出这样的证据。也要看故意弄错时检查会不会失败。
  • GitHub Actions 会在每次上传时自动检查。在公开仓库里,标准运行器是免费的。

术语整理 ​

术语中文名称一句话解释
Test测试自动检查结果是否符合预期的检验
CI持续集成经常合并、经常自动检查的习惯
GitHub ActionsGitHub Actions(自动化工作流)每次上传时自动运行预先设定的任务的功能
YAMLYAML(配置文件格式)用于自动任务设置的文本格式

这一章读完了吗?

学习记录只保存在这个浏览器中。整体进度可以在 全部目录中查看。

下一章:第6章. PR 与审查

参考资料(13 条)
  1. Claude Code 官方文档,「Best practices for Claude Code」. "Claude stops when the work looks done. If it has nothing to run that tells it whether the work actually is done, "looks done" is all it has to go on." code.claude.com (确认日期 2026-11-01) ↩︎

  2. Claude Code 官方文档,「Best practices for Claude Code」. "In practice that makes you the test suite, and every mistake sits there until you happen to notice it." code.claude.com (确认日期 2026-11-01) ↩︎

  3. Claude Code 官方文档,「Best practices for Claude Code」. "If you give it something that comes back pass or fail, Claude can close that loop itself." code.claude.com (确认日期 2026-11-01) ↩︎

  4. Claude Code 官方文档,「Best practices for Claude Code」. "The check can be almost anything, as long as Claude can read the result:" / "A test file" / "A build's exit code" / "A linter" / "A script that diffs output against a fixture" code.claude.com (确认日期 2026-11-01) ↩︎

  5. Claude Code 官方文档,「Best practices for Claude Code」. "If your repo already has one of these, the single most useful line in your CLAUDE.md is the command that runs it." code.claude.com (确认日期 2026-11-01) ↩︎

  6. Claude Code 官方文档,「Best practices for Claude Code」. "In the prompt: run the auth tests after, and keep going until they pass. Claude decides for itself when it's satisfied." code.claude.com (确认日期 2026-11-01) ↩︎

  7. Claude Code 官方文档,「Desktop application」. "Claude can start a dev server and open it in the Browser pane to verify its changes." / "By default, Claude auto-verifies changes after every edit." code.claude.com (确认日期 2026-11-01) ↩︎

  8. Claude Code 官方文档,「Common workflows」. "When asking for tests, be specific about what behavior you want to verify." code.claude.com (确认日期 2026-11-01) ↩︎

  9. Claude Code 官方文档,「Best practices for Claude Code」. "Whichever option you use, ask Claude for evidence: the command it ran and its output, or the screenshot." / "reading the output is faster than rerunning the check yourself." code.claude.com (确认日期 2026-11-01) ↩︎

  10. GitHub 官方文档,「Quickstart for GitHub Actions」. "GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline." / "You can create workflows that run tests whenever you push a change to your repository, or that deploy merged pull requests to production." docs.github.com (确认日期 2026-11-01) ↩︎

  11. GitHub 官方文档,「Billing and usage」. "GitHub Actions usage is free for standard GitHub-hosted runners in public repositories, and for self-hosted runners." docs.github.com (确认日期 2026-11-01) ↩︎

  12. GitHub 官方文档,「Understanding GitHub Actions」. "Workflows are defined in the .github/workflows directory in a repository." docs.github.com (确认日期 2026-11-01) ↩︎

  13. GitHub 官方文档,「Continuous integration」. "Committing code more often detects errors sooner and reduces the amount of code a developer needs to debug when finding the source of an error." / "GitHub runs your CI tests and provides the results of each test in the pull request, so you can see whether the change in your branch introduces an error." docs.github.com (确认日期 2026-11-01) ↩︎