← ClaudeAtlas

golang-testinglisted

Comprehensive Go testing patterns including table-driven tests, mocking, integration testing, benchmarks, and test organization.
aiskillstore/marketplace · ★ 329 · Testing & QA · score 85
Install: claude install-skill aiskillstore/marketplace
# Golang Testing This skill provides guidance on comprehensive testing strategies for Go applications including unit tests, integration tests, benchmarks, and test organization. ## When to Use This Skill - When writing unit tests for Go code - When creating table-driven tests - When mocking dependencies with interfaces - When writing integration tests with test containers - When benchmarking performance-critical code - When organizing test suites and fixtures ## Table-Driven Tests ### Basic Pattern ```go func TestAdd(t *testing.T) { tests := []struct { name string a, b int expected int }{ {"positive numbers", 2, 3, 5}, {"negative numbers", -2, -3, -5}, {"mixed numbers", -2, 3, 1}, {"zeros", 0, 0, 0}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := Add(tt.a, tt.b) if result != tt.expected { t.Errorf("Add(%d, %d) = %d; want %d", tt.a, tt.b, result, tt.expected) } }) } } ``` ### With Error Cases ```go func TestDivide(t *testing.T) { tests := []struct { name string a, b int expected int wantErr bool errString string }{ {"valid division", 10, 2, 5, false, ""}, {"divide by zero", 10, 0, 0, true, "division by zero"}, {"negative result", -10, 2, -5, false, ""}, } for _, tt := range tests { t.Run(tt.