SuperAPI AI 工具集

go-test-quality

测试与质量

查看项目

更新于 10-15 21:37

技能介绍

用途:为 Go 项目提供生产级测试的编写规范与模式参考,把测试当作生产代码对待,强调测试行为而非实现,便于 CI 运行、文档化行为与排障。

主要能力:覆盖子测试(t.Run)组织场景、测试辅助函数(t.Helper、t.Cleanup、带函数式选项的工厂函数)、golden 文件、httptest 的 Recorder 与 Server、testcontainers 集成测试、build tags、TestMain、模糊测试,以及 Go 1.25+ 的 testing/synctest 假时钟并发测试。还涉及 goleak 检测 goroutine 泄漏、t.Context()、b.Loop() 基准测试、t.Attr 与 t.ArtifactDir 等较新报告钩子。

使用方式:按需加载 references/helpers-and-fixtures.md 与 references/integration-testing.md 两个参考文件;按场景选择测试类型(纯函数用表驱动、HTTP handler 用 httptest.NewRecorder、完整路由用 httptest.NewServer、真实数据库用 testcontainers、复杂输出用 golden 文件、不可信输入用模糊测试)。常用命令:go test -race -coverprofile=coverage.out ./... 与 go tool cover -func=coverage.out。

适用场景:Go 服务与库的单元测试、集成测试、并发代码测试与基准测试。

限制:synctest 需 Go 1.25+,Go 1.24 需 GOEXPERIMENT=synctest 且入口为 synctest.Run,低于 1.24 需改用带截止时间的轮询;t.Context() 与 b.Loop() 需 Go 1.24+;t.Attr 需 Go 1.25+,t.ArtifactDir 需 Go 1.26+。资料未提供安装命令、收费与平台信息。