Agent-skills-standard golang-testing
Write unit tests with table-driven patterns and interface mocking in Go. Use when writing Go unit tests, table-driven tests, or using mock interfaces. (triggers: **/*_test.go, testing, unit tests, go test, mocking, testify)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/golang/golang-testing" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-golang-testing && rm -rf "$T"
manifest:
skills/golang/golang-testing/SKILL.mdsource content
Golang Testing
Priority: P0 (CRITICAL)
Implementation Workflow
- Write failing test first — Follow Red-Green-Refactor TDD workflow.
- Use table-driven tests — Define test cases as slice of structs; iterate with
.t.Run() - Mock via interfaces — Use DI and interfaces. Prefer
for auto-generated mocks or manual mocks for simple cases.mockery - Run parallel — Use
for non-sequential tests to speed up CI.t.Parallel() - Clean up resources — Use
to reset state or release DB/file resources.t.Cleanup() - Check coverage — Aim for >80% line coverage. Run
to audit.go test -cover
See table-driven test examples
Tools
- Stdlib:
package usually enough.testing - Testify: Assertions (
,assert
) and mocks.require - Mockery: Auto-generate mocks for interfaces.
- GoMock: Popular mocking framework alternative.
Naming
- Test file:
*_test.go - Test function:
func TestName(t *testing.T) - Example function:
func ExampleName()
Anti-Patterns
- No assert in loops: use
subtests to isolate failures.t.Run - No global mock state: define mocks locally within test scope.
- No skipping race detection: always run
in CI.go test -race