Skip to content
Agentmart
Submit a tool

go-testing

Go testing standards: table-driven tests, testify/require, sentinel errors, mocking, fuzzing, race detection, and test file conventions.

Skill by els0r

IndexedMIT★ 1
Write a review

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/els0r-go-testing

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.

We use your email only for this newsletter. Privacy

About

Go testing standards: table-driven tests, testify/require, sentinel errors, mocking, fuzzing, race detection, and test file conventions. Use this skill whenever writing, reviewing, or discussing Go tests — including unit tests, integration tests, benchmarks, fuzz tests, mocks, or test helpers. Also trigger when the user mentions testify, go-cmp, gock, testcontainers, or asks "how should I test this" for Go code.

Use cases: testing, writing

No 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. 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-testing

What's inside

Skill name
go-testing
Description
Go testing standards: table-driven tests, testify/require, sentinel errors, mocking, fuzzing, race detection, and test file conventions. Use this skill whenever writing, reviewing, or discussing Go tests — including unit tests, integration tests, benchmarks, fuzz tests, mocks, or test helpers. Also trigger when the user mentions testify, go-cmp, gock, testcontainers, or asks "how should I test this" for Go code.
License
MIT
Instructions
183 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Go Testing

Every piece of logic must be tested.

## Test Libraries

| Library | When to use |
|---------|------------|
| `testify/require` | **Default** — fails fast, clear messages |
| `testify/assert` | Only when the test should continue after a failure |
| `google/go-cmp` | Deep comparisons with custom `cmp.Option`s |
| `gock` | Mock HTTP calls — never hit real endpoints in tests |
| `testcontainers` | Integration tests with external services (databases, queues) |

**Favor `require` over `assert`.** It fails immediately and prevents cascading noise.

## Table-Driven Tests

The default pattern. Use for all new tests.

```go
func TestValidateEmail(t *testing.T) {
    tests := []struct {
        name    string
        email   string
        want    bool
        wantErr string // use sentinel errors when possible (see go-style)
    }{
        {"valid email", "user@example.com", true, ""},
        {"empty email", "", false, "email cannot be empty"},
        {"invalid format", "not-an-email", false, "invalid email format"},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got, err := ValidateEmail(tt.email)
            if tt.wantErr != "" {
                require.ErrorContains(t, err, tt.wantErr)
                return
            }
            require.NoError(t, err)
            require.Equal(t, tt.want, got)
        })
    }
}
```

When testing sentinel errors, use `require.ErrorIs(t, err, ErrNotFound)` instead of string matching.

## Test Helpers and Setup

- Mark helpers with `t.Helper()` — no exceptions. Stack traces point to the calling test.
- Use `t.Cleanup(fn)` for teardown instead of `defer` — it runs even if the test calls `t.Fatal`.
- Arrange-act-assert structure. Every time.

```go
func setupTestDB(t *testing.T) *DB {
    t.Helper()
    db, err := NewDB(":memory:")
    require.NoError(t, err)
    t.Cleanup(func() { db.Close() })
    return db
}
```

## Parallel Tests

Use `t.Parallel()` for independent subtests to speed up suites.

```go
for _, tt := range tests {
    t.Run(tt.name, func(t *testing.T) {
        t.Parallel()
        // ...
    })
}
```

Go 1.22+: loop variable is per-iteration scoped — `tt := tt` capture is no longer needed.

## Mocking

Mock via interfaces. Define mocks in the test file, not production code. Keep them minimal.

```go
type MockEmailSender struct {
    Sent []Email
    Err  error // set to simulate failure
}

func (m *MockEmailSender) Send(to, subject, body string) error {
    if m.Err != nil {
        return m.Err
    }
    m.Sent = append(m.Sent, Email{to, subject, body})
    return nil
}
```

## Fuzzing

Use `testing.F` for input-discovery testing on parsers, validators, and serialization.

```go
func FuzzParseConfig(f *testing.F) {
    f.Add([]byte(`{"key": "value"}`))
    f.Add([]byte(`{}`))

    f.Fuzz(func(t *testing.T, data []byte) {
        cfg, err := ParseConfig(data)
        if err != nil {
            return // invalid input is expected
        }
        // round-trip: marshal back and re-parse
        out, err := cfg.Marshal()
        require.NoError(t, err)
        require.Equal(t, cfg, mustParse(t, out))
    })
}

From els0r/skills, MIT.

More from els0r/skills

Signals

Stars
1
Forks
0
Open issues
0
Last commit (this folder)
May 20, 2026 (5 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from els0r

Cite this page

go-testing skill. Agent Mart. https://agentmart.dev/skills/els0r-go-testing (last updated 2026-10-24)