agentleFS
bmcszkbmcszk/agent-skills/skills/go-fluent-testing/SKILL.md

go-fluent-testing

Skill1 starsChanged 2 months agoMITView on GitHub

Go testing with the fluent Given/When/Then DSL across all test tiers: unit (mocks, blackbox), integration (testcontainers, real deps), and E2E (docker-compose, HTTP). ONE methodology — parts struct, newParts(t), .and() chaining, all state in parts. Canonical rules in references/fluent-testing-guideline.md. Use when writing or reviewing ANY Go test: unit, integration, E2E, or choosing the tier for a new test. Keywords: go test, fluent testing, given when then, parts struct, testcontainers, docker-compose, unit test, integration test, e2e test, testify, mocking, blackbox.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 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.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All Go testing — unit, integration, and E2E — in one fluent Given/When/Then methodology.

    line 14
  2. Distinctive:

    No I/O: no DB, no HTTP, no filesystem — mock every dependency via constructor injection (define a small interface at the consumer).

    line 45
  3. Very specific:

    NEVER use direct helper function calls inside fluent Test funcs — everything flows through given/when/then methods (classic units: setup …

    line 119
  4. Distinctive:

    NEVER put validation in the when section (either style)

    line 122
  5. Very specific:

    NEVER use build tags, //nolint, or skip/delete tests

    line 123
  6. Distinctive:

    NEVER leave containers running or skip cleanup (integration/E2E)

    line 124

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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

What I do

All Go testing — unit, integration, and E2E — in one fluent Given/When/Then methodology. One DSL, one parts struct, three tiers.

MANDATORY Reference

ALL Go tests MUST follow: references/fluent-testing-guideline.md (included in this skill directory). It is the single source of truth for the DSL: parts struct, newParts(t), .and() at END of line, all state in parts, no direct helper calls in Test funcs, t.Run promotion, fixtures over inline strings.

Choose the tier

TierDirectoryPackageDependenciesSpeed
Unitnext to code under test<name>_test (external)mocks only, no I/O<10ms/test
Integrationtest/integration/integration_testtestcontainers (real DB/services)100ms–1s/test
E2Etest/e2e/e2e_testdocker-compose services, HTTP on exposed portsseconds/test

Decision rule: test business logic through public APIs → unit; test a component against a real dependency → integration; test a complete user workflow or API contract across services → E2E. Browser-checking a frontend needs chromedp — see the go-browser-tests skill; migrating an existing suite — see the go-fluent-test-migration skill.

Unit rules (blackbox — CRITICAL)

  • Package <name>_test (e.g. handlers_test); test ONLY exported functions/methods; never touch unexported fields or private funcs. This blackbox rule applies to BOTH unit styles below.
  • No I/O: no DB, no HTTP, no filesystem — mock every dependency via constructor injection (define a small interface at the consumer).
  • Speed <10ms per test; naming TestComponent_Scenario.
  • Never: wantErr bool (split into separate tests), build tags, //nolint, deleting or skipping tests.

Unit styles: fluent OR classic

Unit tests accept two layouts — pick per repo convention, keep one per repo, never mix within a package:

Fluent — the full DSL below (parts struct, newParts(t), .and() chaining). Use when the package already has a fluent DSL or the tier is integration/E2E anyway.

Classic — plain test funcs segmented by // given / // when / // then comments. Default for units: no DSL to build, same discipline, less machinery.

func TestService_CreateUser(t *testing.T) {
    // given
    mockRepo := &MockRepository{}
    mockRepo.On("Save", mock.Anything, mock.Anything).Return(nil)
    service := service.NewService(mockRepo)

    // when
    err := service.CreateUser("test@example.com", "Test User")

    // then
    assert.NoError(t, err)
    mockRepo.AssertExpectations(t)
}

Classic rules: the three comments in order, one each; setup only under // given, calls only under // when, assertions only under // then; no section skipped; state stays local to the test func (the parts-struct rule does not apply here).

Fluent pattern (integration & E2E; units when repo is fluent)

func TestService_CreateUser(t *testing.T) {
    _, when, then := newParts(t) // declare only used sections

    when.
        createUser("test@example.com", "Test User")

    then.
        noError().and().
        userPersisted()
}
  • newParts(t) returns p, p, p (given, when, then) over one parts struct that embeds *testing.T, require.New(t), and ALL test state — no local state variables in test funcs.
  • Tier differences live in the given-methods only: unit given builds mocks; integration given starts containers; E2E given waits for compose services. The when/then shape is identical everywhere.

Commands

# Use the project's runner (make or just)
<runner> test-unit         # unit only
<runner> test-integration  # integration only
<runner> test-e2e          # e2e only
<runner> check             # vet + test + lint

Forbidden (all tiers)

  • NEVER use direct helper function calls inside fluent Test funcs — everything flows through given/when/then methods (classic units: setup under // given instead)
  • NEVER put validation in the when section (either style)
  • NEVER use build tags, //nolint, or skip/delete tests
  • NEVER leave containers running or skip cleanup (integration/E2E)

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.