Go Test Quality logo

Go Test Quality

Community
eduardo-sl
go-test-quality

Go testing patterns for production-grade code: subtests, test helpers, fixtures, golden files, httptest, testcontainers, fuzz testing, and testing/synctest. Covers mocking strategies, test isolation, coverage analysis, and test design philosophy. Use when writing tests, improving coverage, reviewing test quality, setting up test infrastructure, or choosing a testing approach. Trigger examples: "add tests", "improve coverage", "write tests for this", "test helpers", "mock this dependency", "integration test", "fuzz test", "flaky test", "synctest", "goroutine leak in tests". Not for: benchmarking methodology (go-performance-review), security testing (go-security-audit), table-driven patterns (go-test-table-driven).

Overview

Publishereduardo-sl
Repositorygo-agent-skills
Skill namego-test-quality
Stars
86
Forks
11
Bundled files
3
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by eduardo-sl on GitHub. Read the source before you install it.

Installation

Install the Go Test Quality AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/eduardo-sl/go-agent-skills/tree/main/skills/(testing)/go-test-quality
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.

Use it in TypingMind

Enable Go Test Quality in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Go Test Quality on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Go Test Quality is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Go Test Quality

Tests are production code. They run in CI on every commit, they document behavior, and they're the first thing you read when a function breaks at 3am. Write them with the same care you'd give to code that handles money.

Community default. A project skill or agent-config rule that explicitly supersedes go-test-quality takes precedence over this one.

Detailed reference material, loaded on demand:

  • references/helpers-and-fixtures.md — test helpers, factory functions with options, t.Cleanup, golden files, mock implementations.
  • references/integration-testing.md — httptest recorder and server, testcontainers, build tags, TestMain, fuzz testing.
  • references/concurrency-and-benchmarks.md — synctest, goleak, t.Context(), b.Loop() benchmarks, t.Attr and artifacts.

Read a reference file only when the summary below is not enough.

1. Test Design Philosophy

Test behavior, not implementation

go
// ✅ Good — tests what the function DOES
func TestTransferFunds_InsufficientBalance(t *testing.T) {
    from := NewAccount("alice", 100)
    to := NewAccount("bob", 0)

    err := TransferFunds(from, to, 150)

    require.ErrorIs(t, err, ErrInsufficientFunds)
    assert.Equal(t, 100, from.Balance(), "sender balance should be unchanged")
    assert.Equal(t, 0, to.Balance(), "receiver balance should be unchanged")
}

// ❌ Bad — tests HOW the function does it
// asserts debit() was called before credit(), rollback() was called,
// internal mutex was locked — breaks on every refactor

One assertion per logical concept

Multiple assert calls are fine when they verify different facets of the SAME behavior (both accounts after a transfer). A test that checks creation AND update AND deletion is three tests pretending to be one.

Name tests like bug reports

When the test fails, the name alone should say what broke:

go
// ✅ Good — reads like a sentence
func TestOrderService_Cancel_RefundsPartiallyShippedItems(t *testing.T) { ... }
func TestParseConfig_ReturnsErrorOnMissingRequiredField(t *testing.T) { ... }

// ❌ Bad — says nothing useful
func TestCancel(t *testing.T) { ... }
func TestRateLimiter_Success(t *testing.T) { ... }

Layout

  • One _test.go per source file (parser.go → parser_test.go), tests in the order of the functions they cover — tools and reviewers navigate by file.
  • Public-API tests live in the pkg_test package so they can only use what callers can; white-box tests stay in pkg.
  • Integration tests sit behind //go:build integration.

2. Subtests for Organized Scenarios

Use t.Run to group related scenarios under a parent test. Each subtest gets its own setup, its own failure, and its own name in CI output:

go
func TestUserService_Create(t *testing.T) {
    svc := setupUserService(t)

    t.Run("succeeds with valid input", func(t *testing.T) {
        user, err := svc.Create(ctx, CreateUserInput{Name: "Alice", Email: "alice@example.com"})
        require.NoError(t, err)
        assert.NotEmpty(t, user.ID)
    })

    t.Run("rejects duplicate email", func(t *testing.T) {
        _, _ = svc.Create(ctx, CreateUserInput{Name: "Alice", Email: "taken@example.com"})
        _, err := svc.Create(ctx, CreateUserInput{Name: "Bob", Email: "taken@example.com"})
        require.ErrorIs(t, err, ErrDuplicateEmail)
    })
}

3. Test Helper Rules

  1. Always call t.Helper() in test utilities so failures point to the caller, not the helper.
  2. Factory functions with functional options for complex test objects — defaults with per-test overrides, never a 15-parameter constructor.
  3. Prefer t.Cleanup over defer — it runs even after t.FailNow() and is scoped to the test, not the function.

Full implementations in references/helpers-and-fixtures.md.

4. Choosing the Test Type

SituationApproachDetails
Pure function, 3+ data casesTable-driven testgo-test-table-driven skill
HTTP handler in isolationhttptest.NewRecorder + mock storereferences/integration-testing.md
Full routing/middleware stackhttptest.NewServerreferences/integration-testing.md
Real database behaviortestcontainers + build tagsreferences/integration-testing.md
Complex output (JSON, HTML, SQL)Golden files in testdata/references/helpers-and-fixtures.md
Parser/validator on untrusted inputFuzz testreferences/integration-testing.md

5. Mocking Rules

  • Interface-based hand-written mocks for small interfaces (≤3 methods): a struct with function fields plus recorded calls.
  • Function injection for simple seams (now func() time.Time).
  • Do NOT mock: value objects, pure functions, the standard library, or your own code in the same package. Test the real thing.
  • If you mock everything, you're testing your mocks, not your code.

6. Parallelism and Coverage

go
func TestSlugify(t *testing.T) {
    t.Parallel() // safe: pure function, no shared state
    // ...
}

Do NOT use t.Parallel() when tests share mutable state, databases, files, or process-level state — t.Setenv and t.Chdir panic in a parallel test for exactly that reason.

bash
go test -race -coverprofile=coverage.out -coverpkg=./... ./...
go tool cover -html=coverage.out   # read the red lines, not the percentage

Coverage finds untested code; it does not measure whether the assertions are any good. Use it to locate gaps, and let CI enforce a floor that only ratchets up (the go-ci skill owns the gate). Without -coverpkg, a package exercised only by another package's tests reports 0%.

7. Testing Concurrent Code

  • Never synchronise a test with time.Sleep — it is slow when it works and flaky when it does not.
  • Go 1.25+: run time-dependent code inside synctest.Test. The bubble's fake clock advances instantly once every goroutine is blocked, and synctest.Wait() replaces "sleep until the background goroutine gets there". On Go 1.24 the API is synctest.Run behind GOEXPERIMENT=synctest. Go 1.27 adds synctest.Sleep(d) (advance and settle in one call) and httptest.NewTestServer(t, h), an in-memory server that works inside the bubble and closes itself.
  • Any package that starts goroutines verifies none leak: goleak.VerifyTestMain(m) in TestMain, or defer goleak.VerifyNone(t). -race finds data races; it does not find a goroutine that never exits.

8. Test Context, Benchmarks, and Artifacts

  • t.Context() (Go 1.24+) instead of context.Background() — it is cancelled before t.Cleanup runs, so blocked work unwinds when the test ends.
  • Benchmarks use for b.Loop() (Go 1.24+): setup runs once, results stay alive without a sink. Add b.ReportAllocs() and compare runs with benchstat.
  • t.Attr (Go 1.25+) emits key/value pairs CI can parse; t.ArtifactDir() with go test -artifacts (Go 1.26+) keeps failing golden output or captured bodies outside the repository.

Examples for both sections: references/concurrency-and-benchmarks.md.

9. Assertion Library Traps

  • Build assert.New(t) / require.New(t) inside each t.Run. An instance created from the parent t reports a subtest's failure against the parent, and the failing subtest itself prints PASS.
  • require, t.Fatal and t.FailNow only on the test goroutine. From a spawned goroutine they cannot stop the test. Send results back on a channel and assert after receiving. go vet's testinggoroutine and golangci-lint's testifylint catch most cases.
  • require for preconditions, assert for independent checks — a failed precondition should stop the test before it nil-panics.
  • assert.Eventually hides timing bugs in polling; prefer synctest.

Anti-Patterns

  • 🔴 Test with no assertions — always passes, proves nothing
  • 🔴 time.Sleep for synchronization — use testing/synctest, channels, or polling
  • 🔴 Test depends on execution order — each test must stand alone
  • 🔴 Mocking everything — you end up testing your mocks, not your code
  • 🟡 Test names like Test1, TestSuccess — name the scenario
  • 🟡 Reaching into private fields — test through the public API
  • 🟡 No edge cases: empty, nil, zero, max values, unicode
  • 🟡 Giant shared setup — each test should set up only what it needs
  • 🟡 context.Background() in a test — use t.Context()
  • 🟡 for range b.N on Go 1.24+ — use for b.Loop()
  • 🟢 Fuzz anything that takes untrusted input
  • 🟢 Golden files for complex output comparisons

Verification Checklist

  1. Every test has meaningful assertions (no empty test bodies)
  2. Test names describe the scenario, not the method
  3. t.Helper() called in every test utility function
  4. t.Cleanup() used for resource teardown
  5. t.Parallel() used where safe, avoided where not
  6. Integration tests guarded with testing.Short() or build tags
  7. Mocks are minimal — only mock external dependencies
  8. No time.Sleep for synchronization anywhere in the suite
  9. Packages that start goroutines verify with goleak
  10. Benchmarks use for b.Loop() and call b.ReportAllocs()
  11. Edge cases covered: empty, nil, zero, boundary values
  12. go test -race ./... passes
  13. Coverage is used to find gaps; CI enforces a ratcheting floor, not a target
  14. testify instances are built per subtest; no require off the test goroutine

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Go Test Quality AI skill do?

Go testing patterns for production-grade code: subtests, test helpers, fixtures, golden files, httptest, testcontainers, fuzz testing, and testing/synctest. Covers mocking strategies, test isolation, coverage analysis, and test design philosophy. Use when writing tests, improving coverage, reviewing test quality, setting up test infrastructure, or choosing a testing approach. Trigger examples: "add tests", "improve coverage", "write tests for this", "test helpers", "mock this dependency", "integration test", "fuzz test", "flaky test", "synctest", "goroutine leak in tests". Not for: benchmar...

Why use Go Test Quality on TypingMind?

Because you install it once and use it with any model. Go Test Quality is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Go Test Quality in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/eduardo-sl/go-agent-skills/tree/main/skills/(testing)/go-test-quality. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Go Test Quality?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Go Test Quality?

As many as you like. As long as a model supports skills, you can use Go Test Quality with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Go Test Quality AI skill free?

Yes. It is published on GitHub by eduardo-sl under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇