go-testing
它能做什么
这项技能指导你的 AI 在用 Go 语言编写或评审测试时的工作。适合希望测试专注、可靠的 Go 开发者,包括终端界面测试。
适用场景
- ✓当你为一个有很多输入情况的 Go 函数编写测试的时候。
- ✓当你要测试一个用 Bubbletea 构建的终端用户界面的时候。
- ✓当你需要黄金文件测试,或需要操作文件系统的测试的时候。
技能链接
https://github.com/Gentleman-Programming/gentle-ai/blob/main/internal/assets/skills/go-testing/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为这个解析器编写表驱动的 Go 测试,包括错误情况。”
每周 5 个新技能,1 分钟读完。
工作原理
技能会根据测试对象选择合适的测试模式,例如对函数使用表驱动测试,对终端界面直接测试模型更新。它保证测试结果确定,并在 short 模式下跳过缓慢的外部测试。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Activation Contract
Load this skill when writing or reviewing Go tests, adding coverage, testing Bubbletea/TUI flows, using teatest, or updating golden files.
Hard Rules
- Prefer table-driven tests for multiple cases; use
t.Run(tt.name, ...). - Test behavior and state transitions, not implementation trivia.
- Use
t.TempDir()for filesystem tests; never rely on a real home directory. - Keep integration tests skippable with
testing.Short()when they run external commands or slow flows. - For Bubbletea, test
Model.Update()directly for state changes; useteatestonly for interactive flows. - Golden files must be deterministic; update only through the repo's
-updatepath and rerun tests without-update. - Use small mocks/interfaces around system or command execution boundaries.
Decision Gates
| Target | Test pattern |
|---|---|
| Pure function or parser | Table-driven unit test. |
| Error behavior | Explicit success and failure cases. |
| File operations | t.TempDir() plus focused assertions. |
| TUI state transition | Direct Model.Update() call with tea.Msg. |
| Full TUI interaction | teatest.NewTestModel(). |
| Rendered output | Golden file test. |
| Real external command | Integration test; skip in -short. |
Execution Steps
- Identify behavior under test and the smallest public boundary that proves it.
- Choose the test pattern from the decision gate.
- Name cases by scenario, not input mechanics.
- Assert outputs, errors, state, and side effects explicitly.
- Run the narrow package test first, then the relevant broader suite.
- For golden updates: run with
-update, inspect diff, then rerun without-update.
Output Contract
Report test files changed, scenarios covered, commands executed, golden files updated, and any skipped integration scope.
References
- references/examples.md — compact table-driven, Bubbletea, teatest, golden, and command examples.
常见问题
什么是黄金文件?
它是一个保存下来的预期输出,测试会与之比较。技能要求它保持确定性。
它如何测试终端界面?
它直接测试状态变化,只有在完整的交互流程中才使用 teatest。
测试会使用真实的主目录吗?
不会。技能要求使用临时文件夹,从不依赖真实的主目录。
详情
作者的原始描述
Trigger: Go tests, go test coverage, Bubbletea teatest, golden files. Apply focused Go testing patterns.
热度
- GitHub 星标
- 8.2k
- 排名
- #12551
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …