# Resources — Unit testing (Go, testify, mocks)

High-trust sources only. In-repo anchors are the ground truth for *how this repo tests*; external
links are for *the general technique* the interview will test. Never cite parametric knowledge —
every non-trivial claim in a lesson links here.

## In-repo ground truth (the primary source for every lesson)
- **`reference/repo-testing-map.md`** — the survey map: the style rules, the two mock generators,
  the `mock/` layout, `testutil.MockDB`, spike's tests by layer, running & coverage. Start here.
- **The house rules:** `.claude/rules/go-test-style.md` (the canonical test structure),
  `.claude/rules/go-code-style.md` (regenerate-mocks + run-tests-after-editing),
  `.claude/agents/unit-tester.md` (the house test-authoring playbook).
- **Mock tooling:** `Makefile` (`gen-mock-v2`, `gen-mock-service`, `unit-test-service`),
  `cmd/utils/mock/` (the cobra CLI + per-service `genXxx.go`), `internal/golibs/tools/mock_struct.go`
  (reflection generator) + `internal/golibs/tools/mock_interface.go` (mockery wrapper).
- **Shared mocks & DB toolkit:** `mock/golibs/database/` (Ext/Tx/Row/Rows, +v5), `mock/testutil/`
  (`MockDB`, `MockExecArgs`/`MockQueryArgs`/`MockScanArray`, `ParseSQL`).
- **spike's tests (the worked examples):** `internal/spike/modules/email/application/commands/create_email_handler_test.go`,
  `.../infrastructure/repositories/email_test.go`, `.../controller/grpc/email_modifier_send_email_test.go`.

## Go testing — the standard library (official)
- **`testing` package** — https://pkg.go.dev/testing — `*testing.T`, `t.Run`, `t.Parallel`, the
  test/benchmark/example model.
- **Go Wiki: Table-Driven Tests** — https://go.dev/wiki/TableDrivenTests — the canonical pattern this
  repo's tests follow.
- **Using Subtests and Sub-benchmarks** — https://go.dev/blog/subtests — `t.Run` for per-case
  subtests, and fine-grained parallelism.
- **Add a test (tutorial)** — https://go.dev/doc/tutorial/add-a-test — the minimal `_test.go` shape.
- **Coverage (`go test -cover`)** — https://go.dev/blog/cover — the coverage tooling behind
  `unit-test-service`; `go tool cover`.

## testify — the assertion + mock library (official)
- **testify (repo + README)** — https://github.com/stretchr/testify — `assert`, `require`, `mock`,
  `suite`; "plays nicely with the standard library."
- **`testify/mock`** — https://pkg.go.dev/github.com/stretchr/testify/mock — `mock.Mock`, `On`,
  `Return`, `Once`, `Anything`, `MatchedBy`, `AssertExpectations`, `AssertExpectationsForObjects`.
- **`testify/assert`** — https://pkg.go.dev/github.com/stretchr/testify/assert — `Equal`, `Nil`,
  `NotEmpty`, `Len`, `ErrorIs` (non-fatal).
- **`testify/require`** — https://pkg.go.dev/github.com/stretchr/testify/require — same API but
  `FailNow` (fatal); used in test helpers.

## mockery — the interface mock generator (official)
- **mockery docs** — https://vektra.github.io/mockery/latest/ — the tool `GenMockInterfaces` wraps
  (v2.46.0 here); `--case underscore`, `--with-expecter`, package config.
- **mockery (repo)** — https://github.com/vektra/mockery — features, the Expecter (`EXPECT()`) API.

## Design wisdom (technique the interview tests)
- **Mocks Aren't Stubs (Martin Fowler)** — https://martinfowler.com/articles/mocksArentStubs.html —
  the classic on test doubles; mocks verify *behaviour*, stubs answer *queries*.
- **Test Double (Fowler bliki)** — https://martinfowler.com/bliki/TestDouble.html — dummy / stub /
  spy / mock / fake, precisely defined.
- **Accept interfaces, return structs** — https://go.dev/wiki/CodeReviewComments#interfaces — the DI
  boundary that makes a struct mockable (the port/adapter seam).

## Community (wisdom — test your understanding on real people)
- **Learn Go with Tests** — https://quii.gitbook.io/learn-go-with-tests/ — the community-standard,
  TDD-first Go testing book; excellent for pressure-testing your instincts.
- **r/golang** — https://www.reddit.com/r/golang/ — mock-vs-real-DB, table-driven-style, and
  when-to-mock debates.
- **Gophers Slack** — https://invite.slack.golangbridge.org/ — #testing.

## The interview angle
- Staples worth rehearsing against this repo's tests: table-driven tests + subtests; test doubles
  (mock vs stub vs fake); dependency injection for testability; what to assert (behaviour vs state);
  coverage as a guide not a goal; the loop-var-capture pitfall in parallel subtests. Ground each in a
  real spike test rather than a toy example.
