정보
이 Claude Skill은 Go에서 테이블 기반 테스트를 구현하고 리팩터링하는 전문적인 지침을 제공합니다. 구조체 설계, 서브테스트 명명, 테스트 매트릭스와 같은 고급 패턴, 그리고 이 접근법의 사용 시기와 회피 시기에 대한 모범 사례를 다룹니다. 일반적인 테스트 전략이나 다른 유형의 테스트가 아닌, 테이블 기반 테스트를 작성, 검토 또는 정리하는 데 특화되어 사용하십시오.
빠른 설치
Claude Code
추천npx skills add eduardo-sl/go-agent-skills -a claude-code/plugin add https://github.com/eduardo-sl/go-agent-skillsgit clone https://github.com/eduardo-sl/go-agent-skills.git ~/.claude/skills/go-test-table-drivenClaude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요
문서
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.
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.
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/setupFuncfunction 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.wantRedirectin 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
- Every field must vary between at least 2 cases. A field with the same value everywhere is setup — move it outside the table.
- Name the
namefield as a short sentence describing the scenario:"returns error for negative amount", not"case1"or"success". wantErr boolfor "should it error?" — check it first andreturnearly in the loop body.wantErrIs errorwith a sentinel when the caller must detect a specific error; assert withrequire.ErrorIs.- ≤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
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 := ttcapture 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 |
setupFunc field in struct | Extract to separate subtests with explicit setup |
if tt.shouldX in loop body | Each branch is a different test — split it |
| Same 3 fields identical in every case | Move to shared setup outside the table |
| Adding a case requires understanding all others | Table has grown beyond its useful life |
Decision Flowchart
-
Is the function pure (input → output, no side effects)? Yes → table test is probably ideal. Go to 2. No → consider explicit subtests first.
-
Do all cases share the exact same assertion pattern? Yes → table test. Go to 3. No → explicit subtests.
-
Can each case be expressed in ≤5 struct fields? Yes → table test. No → split by scenario into separate test functions.
-
Is the loop body ≤10 lines? Yes → you're golden. No → the table is hiding complexity. Refactor.
Verification Checklist
- Table struct has only fields that vary between cases
- Every case has a descriptive
namefield - Loop body is ≤10 lines with no branching
- No
setupFuncormockFuncfields in the struct wantErris a simple bool or sentinel, not a string match- Cases cover: happy path, error path, edge cases (empty, nil, zero, max)
t.Runwraps each case for named subtestst.Parallel()used only when function is side-effect-free
GitHub 저장소
자주 묻는 질문
go-test-table-driven Skill이란 무엇인가요?
go-test-table-driven은(는) eduardo-sl이(가) 만든 Claude Skill입니다. Skill은 Claude가 필요할 때 불러오는 지침과 리소스를 묶어 추가 프롬프트 없이 go-test-table-driven 관련 작업을 수행할 수 있게 합니다.
go-test-table-driven은(는) 어떻게 설치하나요?
이 페이지의 설치 명령을 사용하세요. go-test-table-driven을(를) Claude Code 플러그인으로 추가하거나 저장소를 skills 디렉터리에 복제한 다음 Claude를 다시 시작해 Skill을 불러옵니다.
go-test-table-driven은(는) 어떤 카테고리에 속하나요?
go-test-table-driven은(는) 테스팅 카테고리에 속합니다.
go-test-table-driven은(는) 무료로 사용할 수 있나요?
네. go-test-table-driven은(는) AIMCP에 등록되어 있으며 무료로 설치할 수 있습니다.
연관 스킬
이 Claude Skill은 MMLU, GSM8K를 포함한 60개 이상의 표준화된 학술 과제에서 LLM 성능을 벤치마크하기 위해 lm-evaluation-harness를 실행합니다. 개발자들이 모델 품질을 비교하고, 학습 진행 상황을 추적하거나 학술 결과를 보고할 수 있도록 설계되었습니다. 이 도구는 HuggingFace와 vLLM 모델을 포함한 다양한 백엔드를 지원합니다.
이 스킬은 cron 표현식을 사용하여 Worker를 스케줄링하기 위한 Cloudflare Cron Triggers 구현에 관한 포괄적인 지식을 제공합니다. 주기적 작업, 유지보수 작업, 자동화된 워크플로우 설정 방법을 다루며, 잘못된 cron 표현식이나 시간대 문제 같은 일반적인 이슈들을 해결하는 방법을 포함합니다. 개발자들은 이를 통해 스케줄된 핸들러 구성, cron 트리거 테스트, Workflows 및 Green Compute와의 연동 작업을 수행할 수 있습니다.
이 Claude Skill은 Python 스크립트를 통해 로컬 웹 애플리케이션을 테스트하기 위한 Playwright 기반 툴킷을 제공합니다. 프론트엔드 검증, UI 디버깅, 스크린샷 캡처, 로그 확인 기능을 지원하며 서버 라이프사이클을 관리합니다. 브라우저 자동화 작업에 사용하되 컨텍스트 오염을 방지하기 위해 소스 코드를 읽지 않고 스크립트를 직접 실행하세요.
이 스킬은 테스트 통과를 확인한 후 체계적인 통합 옵션을 제시하여 개발자가 완성된 작업을 마무리하도록 돕습니다. 구현이 완료된 후 머지, PR 생성, 브랜치 정리와 같은 워크플로우를 안내합니다. 코드가 준비되고 테스트가 완료되었을 때 개발 프로세스를 체계적으로 마무리하기 위해 사용하세요.
