← ClaudeAtlas

go-testslisted

Enforces idiomatic Go testing — table-driven cases with subtests, the standard library over assertion frameworks, t.Cleanup for teardown, httptest for HTTP, golden files, fuzzing, and benchmarks that measure. Use when writing or reviewing Go tests, and when the user mentions table tests, t.Run, t.Parallel, testify, testdata, golden files, httptest, go test -race, coverage, benchmarks, fuzz, or asks "how do I test this in Go".
CasLubbers/code-design-skills · ★ 1 · Testing & QA · score 62
Install: claude install-skill CasLubbers/code-design-skills
# Go tests ## Table-driven is the default One test function, a slice of cases, a subtest per case. Adding coverage means adding a struct literal. ```go func TestParseDuration(t *testing.T) { tests := map[string]struct { in string want time.Duration wantErr bool }{ "seconds": {in: "30s", want: 30 * time.Second}, "compound": {in: "1h30m", want: 90 * time.Minute}, "zero": {in: "0", want: 0}, "empty": {in: "", wantErr: true}, "bad unit": {in: "5x", wantErr: true}, } for name, tc := range tests { t.Run(name, func(t *testing.T) { t.Parallel() got, err := ParseDuration(tc.in) if tc.wantErr { if err == nil { t.Fatal("want error, got nil") } return } if err != nil { t.Fatalf("unexpected error: %v", err) } if got != tc.want { t.Errorf("got %v, want %v", got, tc.want) } }) } } ``` A map keys cases by name and randomises order, which surfaces inter-case dependencies. Name cases after the behaviour, not `case1`. `t.Run` gives each one its own line in the output and lets you run one with `-run TestParseDuration/bad_unit`. ## Failure messages carry the values The reader is looking at CI output, not your screen. ```go // Good t.Errorf("ParseDuration(%q) = %v, want %v", tc.in, got, tc.want) // Bad — tells you nothing t.Error("wrong result") ``` `t