agentleFS
bmcszkbmcszk/agent-skills/skills/go-tests/SKILL.md

go-tests

Skill2 starsChanged 15 days agoMITView on GitHub

Use when adding, changing, or reviewing Go unit, integration, or E2E tests or test stages, when choosing which test level a code change needs, when choosing between integration and E2E tests, when writing a benchmark or an Example, when reading a coverage report, or when picking the test runtime. Covers unit tests for pure public functions, integration tests on Docker Compose, and E2E tests on the project's full-stack runtime, all in the fluent given/when/then stage pattern (*_test.go plus *_stage_test.go). Also use when migrating an existing Go test suite onto that fluent pattern. Browser tests: see go-browser-tests.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 3 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Test data, fake upstream servers, async checks, or test file layout: test-data-and-config.md.

    line 36
  2. Distinctive:

    Test only pure, easily testable functions, ideally public ones.

    line 48
  3. Very specific:

    Before handoff, run on new unit files in the diff (skip test/integration/ and test/e2e/):

    line 50
  4. Very specific:

    Always use a file pair. *_test.go holds scenarios.

    line 59
  5. Very specific:

    Use the fluent stage: given, when, then := newStage(t).

    line 60
  6. Very specific:

    No build tags. No mocks. No //nolint.

    line 61
  7. Very specific:

    When the code paces output (interval, backoff, debounce) or has timeouts, assert the pacing and test at least one duration past the server …

    line 64
  8. Very specific:

    Use the repo runner, usually make or just.

    line 65
  9. Distinctive:

    Do not patch first. Record the bug (what failed, how to reproduce) before you change code, then fix it with a test that fails first.

    line 69

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Go tests

Go unit, integration, and E2E tests. These conventions are required. Do not swap them for a shorter generic approach.

Shared Go rules are in ../go-dev/SKILL.md.

Choose the level

Choose by behaviour, not by convenience.

LevelUse forRuns onRead
UnitPure public functions: validation, parsing, mapping, formatting, deterministic calculations, simple business rulesNo servicesunit-tests.md
IntegrationDatabases, queues, streams, storage, service componentsDocker Composefluent-stage-tests.md, integration-tests.md
E2EAPI contracts, multi-service workflows, deployed service wiringThe project's full-stack runtime (for example Tilt or a deployed stack)fluent-stage-tests.md, e2e-tests.md

Runtime and command choice: test-orchestration.md.

More references, each with its load condition:

  • Growing or splitting a stage, adding a stage file, or changing the stage type: stage-structure.md.
  • Test data, fake upstream servers, async checks, or test file layout: test-data-and-config.md.
  • Comparing implementations or input sizes, or writing a new benchmark: benchmarks.md.
  • Reading a coverage report or choosing which untested path to attack next: coverage.md.
  • A runnable Example* next to a public API: examples.md.
  • Fuzzing a target, or faking time with testing/synctest: unit-tests.md.
  • Moving an existing suite onto the fluent stage DSL: fluent-migration.md.

Hard rules: unit

  • At most one unit test file per source file. Name it after the file under test with a _test.go suffix (foo.go becomes foo_test.go). Not every source file needs a unit test. Do not dump tests for many source files into one test file.
  • Blackbox tests in package <name>_test.
  • A unit test feeds inputs and asserts outputs and errors on pure code. If the test needs a hand-written type that satisfies a production interface, write an integration or E2E test instead.
  • Test only pure, easily testable functions, ideally public ones.
  • Assert on direct inputs, outputs, and returned errors.
  • Before handoff, run on new unit files in the diff (skip test/integration/ and test/e2e/): git diff --name-only --diff-filter=A origin/<default-branch> -- '*_test.go' | grep -vE '/test/(integration|e2e)/' | xargs rg --files-without-match '^package \w+_test$'. Empty output means pass.
  • One Test* function per outcome. Assert that outcome directly (require.NoError, require.Error, and the like).
  • A table shares inputs for one outcome only. Put another outcome in its own Test* function.
  • Mixed success/error table fields (wantErr, wantError, wantFail, and the like) bundle two outcomes in one row. Do not write them.
  • Mark sections with // given, // when, and // then. given is explicit setup only (no asserts, not the call under test). when is usually one call under test. then holds all asserts.

Hard rules: integration and E2E

  • Integration tests live in test/integration/ with package integration_test. E2E tests live in test/e2e/ with package e2e_test.
  • Always use a file pair. *_test.go holds scenarios. *_stage_test.go holds the stage.
  • Use the fluent stage: given, when, then := newStage(t). One given, one when, one then per test. given is explicit stage setup only (no asserts, no action under test). when is usually one -ing call under test. then holds all asserts. Do not blur phases; details in fluent-stage-tests.md.
  • No build tags. No mocks. No //nolint. Never skip or delete a test to get green.
  • Tests run on the host and connect to exposed ports. Clean up external resources with t.Cleanup, registered in the given method that creates them.
  • Wire behaviour (streaming formats, delivery headers, retry exhaustion) needs at least one E2E assertion each, even when unit tests cover the parts. Only E2E proves the real server, router, and middleware are wired.
  • When the code paces output (interval, backoff, debounce) or has timeouts, assert the pacing and test at least one duration past the server limits (for example http.Server WriteTimeout). A suite where every stream ends in 100 ms cannot see a cut at 10 s.
  • Use the repo runner, usually make or just.

Bugs found by tests

Do not patch first. Record the bug (what failed, how to reproduce) before you change code, then fix it with a test that fails first.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.