go-test-table-driven
Deep dive on table-driven tests in Go: when to use them, when to avoid them, struct design, subtest naming, advanced patterns like test matrices and shared…
Skill by eduardo-sl
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/eduardo-sl-go-test-table-driven
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: design, testing, data, writing
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/go-test-table-driven
Tools it pre-approves 7
From allowed-tools in SKILL.md: the agent may use these without asking you each time.
ReadEditWriteGlobGrepBash(go:*)Bash(gofmt:*)
What's inside
- Skill name
go-test-table-driven- Description
- Deep dive on table-driven tests in Go: when to use them, when to avoid them, struct design, subtest naming, advanced patterns like test matrices and shared setup, and refactoring bloated tables into clean ones. Use when writing table-driven tests, refactoring test tables, reviewing table test structure, or deciding whether table-driven is the right approach. Trigger examples: "table-driven test", "table test", "test cases struct", "test matrix", "parametrize tests", "data-driven test", "refactor test table". Not for: general test strategy, mocks, golden files, fuzzing (go-test-quality), benchmarks (go-performance-review).
- License
- MIT
- Compatibility
- Designed for Claude Code or similar AI coding agents working on Go projects. Requires the Go toolchain.
- Allowed tools
- Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(gofmt:*)
- Metadata
- author: eduardo-sl · version: 1.2.2
- Instructions
- 154 lines in SKILL.md · view on GitHub
Before installing
- Pre-approves some shell commands
Files (3)
- SKILL.md
- patterns.md · references/
- refactoring.md · references/
SKILL.md (first lines)
# Go Table-Driven Tests
Table-driven tests are a powerful Go idiom — when used correctly. Most
codebases either underuse them (10 copy-paste tests) or overuse them
(complex branching logic in a 200-line struct). This skill covers the
sweet spot.
> Community default. A project skill or agent-config rule that explicitly
> supersedes `go-test-table-driven` takes precedence over this one.
Detailed reference material, loaded on demand:
- `references/patterns.md` — full worked examples: canonical tables,
`wantErr`/`wantErrIs`, parallel tables, map-based tables, error-only
tables, struct alignment for readability.
- `references/refactoring.md` — recognizing bloated tables and rewriting
them as explicit subtests, with before/after examples.
Read a reference file only when the summary below is not enough for the
task at hand.
## 1. When Table-Driven Tests Shine
Use a table only when ALL of these are true:
- **Same function** under test across all cases
- **Same assertion pattern** — input in, output out, compare
- **Cases differ only in data**, not in setup or verification logic
- **3+ cases** — fewer than 3, explicit tests are clearer
Canonical use case: pure functions, parsers, validators, formatters.
```go
func TestParseSize(t *testing.T) {
tests := []struct {
name string
input string
want int64
wantErr bool
}{
{name: "plain bytes", input: "1024", want: 1024},
{name: "kilobytes suffix", input: "4KB", want: 4096},
{name: "empty string", input: "", wantErr: true},
{name: "negative size", input: "-1", wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseSize(tt.input)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}
```
Every case has the same shape, the loop body is a few lines, and adding
a case is one struct literal. No branching, no conditionals.
## 2. When NOT to Use Table-Driven Tests
- **Complex per-case setup** — `setupMock`/`setupFunc` function fields in
the struct mean the table is hiding complexity. Write explicit subtests.
- **Fewer than 3 cases** — the struct definition is more code than two
plain test functions.
- **Multiple branching paths** — `if tt.shouldError` / `if tt.wantRedirect`
in the loop body means each branch is a different test pretending to
share a structure. Split it.
See `references/refactoring.md` for before/after rewrites of each smell.
## 3. Struct Design Rules
1. **Every field must vary between at least 2 cases.** A field with the
same value everywhere is setup — move it outside the table.
2. **Name the `name` field as a short sentence** describing the scenario:
`"returns error for negative amount"`, not `"case1"` or `"success"`.
3. **`wantErr bool` for "should it error?"** — check it first and `return`
early in the loop body.
4. **`wantErrIs error` with a sentinel** when the caller must detect a
specific error; assert with `require.ErrorIs`.
5. **≤5 fields.** More means the scenario is too complex for a table —
split into separate test functions.
Full field-pattern examples are in `references/patterns.md`.
## 4. The Loop Body Must Be Trivial
The point of a table test is identical execution logic for every case.
Keep the loop body under ~10 lines: call, error check, comparison.
If it accumulates conditionals or per-case setup, the table has outgrown
its usefulness — refactor into explicit subtests.
## 5. Parallel Table Tests
```go
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := Transform(tt.input)
assert.Equal(t, tt.want, got)
})
}
```
- Go 1.22+ scopes the loop variable per iteration — `tt := tt` capture is
unnecessary. For Go <1.22 the capture is still required.
- Only use `t.Parallel()` when the function under test has no side
effects and no shared mutable state.
## 6. Refactoring Bloated Tables
| Symptom | Fix |
|---|---|
| Struct has 8+ fields | Split into multiple test functions by scenario |From eduardo-sl/go-agent-skills, MIT.
More from eduardo-sl/go-agent-skills
- 0.676score
go-cli
eduardo-sl
Build command-line tools in Go: flag handling, subcommands, stdin/stdout discipline, exit codes, signal handling, and when Cobra/Viper earn their weight over…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-modernize
eduardo-sl
Modernize Go code to use current language features and standard library additions, Go 1.21 through 1.27: generics and generic methods, log/slog, errors.Join…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-graphql
eduardo-sl
Build GraphQL servers in Go with gqlgen: schema-first generation, resolver structure, the N+1 problem and dataloaders, complexity and depth limits, error…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-grpc
eduardo-sl
gRPC services in Go beyond the basics: proto design, status codes and error details, interceptors, deadlines, streaming, health checks, and graceful shutdown.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-interface-design
eduardo-sl
Go interface design patterns: implicit interfaces, consumer-side definition, interface compliance verification, composition, the…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-api-design
eduardo-sl
HTTP/REST API design for Go services: handlers, ServeMux routing, middleware, request validation, pagination, idempotency, health checks, error responses, and…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-coding-standards
eduardo-sl
Go coding standards and style conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-context
eduardo-sl
Correct usage of context.Context in Go: propagation, cancellation, timeouts, deadlines, values, and common anti-patterns.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-data-structures
eduardo-sl
Correct use of Go's built-in data structures: slices (nil vs empty, append semantics, aliasing, preallocation), maps (comma-ok, sets, iteration order)…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-documentation
eduardo-sl
Go documentation conventions: godoc comments, package docs, testable Example functions, deprecation notices, doc links, and project docs (README, CHANGELOG…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-error-handling
eduardo-sl
Go error handling patterns, wrapping, sentinel errors, custom error types, and the errors package.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-naming
eduardo-sl
Go naming conventions for packages, files, types, functions, methods, receivers, variables, constants, errors, acronyms and tests, grounded in Effective Go…
SkillAFreshness: A★ 82Claude Code +9
Signals
- Stars
- 82
- Forks
- 10
- Open issues
- 0
- Last commit (this folder)
- Oct 14, 2026 (15 days ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 1.2.2
- License
- MIT
- Repository
- github.com/eduardo-sl/go-agent-skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from eduardo-sl
- 0.676score
go-cli
eduardo-sl
Build command-line tools in Go: flag handling, subcommands, stdin/stdout discipline, exit codes, signal handling, and when Cobra/Viper earn their weight over…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-api-design
eduardo-sl
HTTP/REST API design for Go services: handlers, ServeMux routing, middleware, request validation, pagination, idempotency, health checks, error responses, and…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-graphql
eduardo-sl
Build GraphQL servers in Go with gqlgen: schema-first generation, resolver structure, the N+1 problem and dataloaders, complexity and depth limits, error…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-grpc
eduardo-sl
gRPC services in Go beyond the basics: proto design, status codes and error details, interceptors, deadlines, streaming, health checks, and graceful shutdown.
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-interface-design
eduardo-sl
Go interface design patterns: implicit interfaces, consumer-side definition, interface compliance verification, composition, the…
SkillAFreshness: A★ 82Claude Code +9 - 0.676score
go-coding-standards
eduardo-sl
Go coding standards and style conventions grounded in Effective Go, Go Code Review Comments, and production-proven idioms.
SkillAFreshness: A★ 82Claude Code +9
Cite this page
go-test-table-driven skill. Agent Mart. https://agentmart.dev/skills/eduardo-sl-go-test-table-driven (last updated 2026-10-24)