跳到正文
Skillpedia
测试8.2k · #12551

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/Gentleman-Programming/gentle-ai/blob/main/internal/assets/skills/go-testing/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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; use teatest only for interactive flows.
  • Golden files must be deterministic; update only through the repo's -update path 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

  1. Identify behavior under test and the smallest public boundary that proves it.
  2. Choose the test pattern from the decision gate.
  3. Name cases by scenario, not input mechanics.
  4. Assert outputs, errors, state, and side effects explicitly.
  5. Run the narrow package test first, then the relevant broader suite.
  6. 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

常见问题

什么是黄金文件?

它是一个保存下来的预期输出,测试会与之比较。技能要求它保持确定性。

它如何测试终端界面?

它直接测试状态变化,只有在完整的交互流程中才使用 teatest。

测试会使用真实的主目录吗?

不会。技能要求使用临时文件夹,从不依赖真实的主目录。

详情

作者的原始描述

Trigger: Go tests, go test coverage, Bubbletea teatest, golden files. Apply focused Go testing patterns.

repo: Gentleman-Programming/gentle-ai

热度

GitHub 星标
8.2k
排名
#12551
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能