Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
cxuu avatar

Go Testing

  • 981 installs
  • 137 repo stars
  • Updated June 20, 2026
  • cxuu/golang-skills

go-testing is a Claude Code skill that generates and reviews idiomatic Go test code using table-driven tests, subtests, helpers, and cmp.Diff for developers who need reliable unit test coverage.

About

go-testing is a Go testing skill grounded in Google and Uber style guides that teaches table-driven tests, subtests, parallel execution, test helpers, test doubles, and assertions with github.com/google/go-cmp. The skill specifies when to use t.Error versus t.Fatal, patterns for subtests and parallel tests, and cmp.Diff for struct comparisons instead of brittle equality checks. Developers reach for go-testing when asked to write a test for a Go function, refactor flaky tests, or review test quality in packages and services. The skill explicitly excludes benchmark performance testing, which belongs in the separate go-performance skill.

  • Applies to writing, reviewing, or improving Go test code including table-driven tests, subtests, parallel tests, test he
  • Triggers automatically when a user asks to write a test for any Go function
  • Enforces normative failure messages that include function name, inputs, actual vs expected without needing to read test
  • Recommends t.Error vs t.Fatal, t.Helper(), t.Cleanup(), and cmp.Diff usage patterns
  • Sources patterns from Google and Uber Go Style Guides

Go Testing by the numbers

  • 981 all-time installs (skills.sh)
  • +42 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Ranked #537 of 2,153 Testing & QA skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/cxuu/golang-skills --skill go-testing

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs981
repo stars137
Security audit3 / 3 scanners passed
Last updatedJune 20, 2026
Repositorycxuu/golang-skills

How do you write idiomatic table-driven Go tests?

Generate, review, and improve high-quality Go test code using table-driven tests, subtests, helpers, and cmp.Diff assertions.

Who is it for?

Go developers writing or reviewing unit tests in services, CLIs, and libraries who want Google/Uber-style test patterns.

Skip if: Teams needing Go benchmark profiling or performance regression tests covered by the separate go-performance skill.

When should I use this skill?

A developer asks to write, review, or improve Go tests, including table-driven tests, subtests, or cmp.Diff comparisons.

What you get

Go _test.go files with table-driven cases, subtests, helpers, and cmp.Diff assertions.

  • _test.go files
  • table-driven test cases
  • cmp.Diff assertions

Files

SKILL.mdMarkdownGitHub ↗

Go Testing

Compatibility: Diff examples may use github.com/google/go-cmp.

Resource Routing

  • scripts/gen-table-test.sh - Run when generating a table-driven test scaffold.
  • assets/table-test-template.go - Use as a copyable table-test starting point.
  • references/TABLE-DRIVEN-TESTS.md - Read when choosing table tests, subtests, or parallel test patterns.
  • references/TEST-HELPERS.md - Read when writing helpers, fixtures, cleanup, or test doubles.
  • references/TEST-ORGANIZATION.md - Read when structuring packages, black-box tests, or larger test suites.
  • references/VALIDATION-APIS.md - Read when choosing t.Error, t.Fatal, cmp.Diff, or assertion style.
  • references/INTEGRATION.md - Read when testing external services, HTTP handlers, databases, or long-running setup.

Quick Reference

PatternUse When
t.ErrorDefault — report failure, keep running
t.FatalSetup failed or continuing is meaningless
cmp.DiffComparing structs, slices, maps, protos
Table-drivenMany cases share identical logic
SubtestsNeed filtering, parallel execution, or naming
t.Helper()Any test helper function (call as first statement)
t.Cleanup()Teardown in helpers instead of defer

---

Useful Test Failures

Normative: Test failures must be diagnosable without reading the test
source.

Every failure message must include: function name, inputs, actual (got), and expected (want). Use the format YourFunc(%v) = %v, want %v.

// Good:
t.Errorf("Add(2, 3) = %d, want %d", got, 5)

// Bad: Missing function name and inputs
t.Errorf("got %d, want %d", got, 5)

Always print got before want: got %v, want %v — never reversed.

---

No Assertion Libraries

Normative: Do not use assertion libraries. Use cmp.Diff for complex
comparisons.
if diff := cmp.Diff(want, got); diff != "" {
    t.Errorf("GetPost() mismatch (-want +got):\n%s", diff)
}

For protocol buffers, add protocmp.Transform() as a cmp option. Always include the direction key (-want +got) in diff messages. Avoid comparing JSON/serialized output — compare semantically instead.

---

t.Error vs t.Fatal

Normative: Use t.Error by default to report all failures in one run.
Use t.Fatal only when continuing is impossible.

Choose `t.Fatal` when:

  • Setup fails (DB connection, file load)
  • The next assertion depends on the previous one succeeding (e.g., decode after

encode)

Never call `t.Fatal`/`t.FailNow` from a goroutine other than the test goroutine — use t.Error instead.

---

Table-Driven Tests

See assets/table-test-template.go when scaffolding a new table-driven test and need the canonical struct, loop, and subtest layout.
Advisory: Use table-driven tests when many cases share identical logic.

Use table tests when: all cases run the same code path with no conditional setup, mocking, or assertions. A single shouldErr bool is acceptable.

Don't use table tests when: cases need complex setup, conditional mocking, or multiple branches — write separate test functions instead.

Key rules:

  • Use field names when cases span many lines or have same-type adjacent fields
  • Include inputs in failure messages — never identify rows by index
Validation: After generating or modifying tests, run go test -run TestXxx -v to verify the tests compile and pass. Fix any compilation errors before proceeding.

---

Test Helpers

Normative: Test helpers must call t.Helper() first and use t.Cleanup()
for teardown.
func setupTestDB(t *testing.T) *sql.DB {
    t.Helper()
    db, err := sql.Open("sqlite3", ":memory:")
    if err != nil {
        t.Fatalf("Could not open database: %v", err)
    }
    t.Cleanup(func() { db.Close() })
    return db
}

---

Test Error Semantics

Advisory: Test error semantics, not error message strings.
// Bad: Brittle string comparison
if err.Error() != "invalid input" { ... }

// Good: Semantic check
if !errors.Is(err, ErrInvalidInput) { ... }

For simple presence checks when specific semantics don't matter:

if gotErr := err != nil; gotErr != tt.wantErr {
    t.Errorf("f(%v) error = %v, want error presence = %t", tt.input, err, tt.wantErr)
}

---

Related Skills

  • Error testing: See go-error-handling when testing error semantics with errors.Is/errors.As or sentinel errors
  • Interface mocking: See go-interfaces when creating test doubles by implementing interfaces at the consumer side
  • Naming test functions: See go-naming when naming test functions, subtests, or test helper utilities
  • Linter integration: See go-linting when running linters alongside tests in CI or pre-commit hooks

Related skills

How it compares

Pick go-testing over generic test-generation skills when the codebase is Go and you need idiomatic table-driven patterns rather than framework-agnostic examples.

FAQ

Does go-testing cover Go benchmark tests?

go-testing does not cover benchmark performance testing. The skill readme directs benchmark work to the separate go-performance skill and focuses on unit tests, table-driven cases, subtests, and cmp.Diff assertions.

Which assertion library does go-testing recommend?

go-testing recommends github.com/google/go-cmp for cmp.Diff struct comparisons. The skill is compatible with the go-cmp module and follows Google and Uber style guide testing patterns.

Is Go Testing safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Testing & QAbackendtesting

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.