Go Testing Tabledriven

Guides Go test structure — a slice of named struct cases looped through t.Run so every case is an isolated, individually-runnable subtest; t.Helper in assertion helpers so failures point at the caller; t.Cleanup (LIFO) over defer for teardown; t.Parallel for concurrency (and the Go 1.22 loop-var change that removes the old `tc := tc` copy); t.Errorf to continue vs t.Fatalf to stop this test's goroutine; got-before-want messages that identify the input; cmp.Diff over reflect.DeepEqual; golden files under testdata/ with a -update flag; t.TempDir and TestMain. Auto-invokes when writing or editing _test.go files, table-driven tests, t.Run subtests, t.Helper, t.Cleanup, t.Parallel, golden files, or on "write tests for this" / "add a test case" requests. Routes fuzzing, benchmarks, and synctest to go-testing-advanced.

ctoth 831ef7c 3 files · 30.6 KB Updated

File contents

ctoth/golang-skills-plugin/tree/main/plugins/golang/skills/go-testing-tabledriven commit 831ef7c3a4

Frequently asked questions

npx skillmds@latest add ctoth/go-testing-tabledriven