Skip to content
Skill

golang-testing

by xu-xiang

AI Summary

A comprehensive Go testing booster that teaches TDD methodology, table-driven tests, benchmarking, and fuzzing patterns for Claude Code users. Ideal for Go developers aiming to write reliable, well-tested code following idiomatic Go practices.

Install

Copy this and paste it into Claude Code, Cursor, or any AI assistant:

I want to install the "golang-testing" skill in my project.

Please run this command in my terminal:
# Install skill into your project
mkdir -p .claude/skills/golang-testing && curl --retry 3 --retry-delay 2 --retry-all-errors -o .claude/skills/golang-testing/SKILL.md "https://raw.githubusercontent.com/xu-xiang/everything-claude-code-zh/main/skills/golang-testing/SKILL.md"

Then restart Claude Code (or reload the window in Cursor) so the skill is picked up.

Description

Go 测试模式,包括表格驱动测试、子测试、基准测试、模糊测试和测试覆盖率。遵循具有惯用 Go 实践的 TDD 方法论。

Go 测试模式 (Testing Patterns)

遵循测试驱动开发(TDD)方法论,编写可靠且易于维护的 Go 测试的全面模式。

何时激活

• 编写新的 Go 函数或方法时 • 为现有代码增加测试覆盖率时 • 为性能关键型代码创建基准测试(Benchmarks)时 • 为输入验证实现模糊测试(Fuzz tests)时 • 在 Go 项目中遵循 TDD 工作流时

红-绿-重构 (RED-GREEN-REFACTOR) 循环

` RED → 先编写一个失败的测试 GREEN → 编写最少的代码使测试通过 REFACTOR → 在保持测试通过的同时改进代码 REPEAT → 继续处理下一个需求 `

Go 中的分步 TDD

`go // 步骤 1:定义接口/签名 // calculator.go package calculator func Add(a, b int) int { panic("not implemented") // 占位符 } // 步骤 2:编写失败的测试 (RED) // calculator_test.go package calculator import "testing" func TestAdd(t *testing.T) { got := Add(2, 3) want := 5 if got != want { t.Errorf("Add(2, 3) = %d; want %d", got, want) } } // 步骤 3:运行测试 - 验证失败 (FAIL) // $ go test // --- FAIL: TestAdd (0.00s) // panic: not implemented // 步骤 4:实现最少代码 (GREEN) func Add(a, b int) int { return a + b } // 步骤 5:运行测试 - 验证通过 (PASS) // $ go test // PASS // 步骤 6:如果需要则进行重构,并验证测试仍然通过 `

Discussion

0/2000
Loading comments...

Health Signals

MaintenanceCommitted 1mo ago
Active
Adoption100+ stars on GitHub
177 ★ · Growing
DocsMissing or thin
Undocumented

GitHub Signals

Stars177
Forks40
Issues1
Updated1mo ago
View on GitHub
MIT License

My Fox Den

Community Rating

Sign in to rate this booster

Works With

Claude Code