A standalone course · Catch up on this repo + interview prep

Unit testing, from newcomer to interview-ready

How this repo writes the tests that keep it honest — Go testing, table-driven cases, testify mocks, and the mock generators — anchored on your own spike service.

Two-thousand-plus test files, all cut from the same cloth: table-driven cases, testify mocks injected into the code under test, a house DB toolkit that fakes Postgres without a database, and generated mocks you regenerate with one Make target. This course teaches that whole loop — write → mock → generate → run → cover — grounded in spike's real tests at every layer. It's the craft you use every day and the Go skill most interviews probe.

How to use this Do one lesson, take its quiz from memory (no peeking), then skim the matching row of the cheat sheet. Come back a day later and re-take it — spacing beats cramming. You know the rhythm by now. Stuck? Ask me — I'm your teacher, not just the author.
Scope — unit tests only This course is the go test ./internal/..., testify-mock world. It deliberately stops at the BDD/E2E boundary: no features/, no gandalf, no local/run.bash bdd, no real-database tests. We name that line in Lesson 1 and stay on the unit side of it.

Part 1 — The unit-test foundation available now

Go's testing model and the house structure every test here follows.

1 · What a unit test is here

The scope boundary, the tools (go test + testify + mock/), the map.

ready

2 · Table-driven tests & subtests

t.Run per case, t.Parallel, timeouts, and the loop-var pitfall.

ready

3 · The house structure

newSuite + assertExpected + arrange/act/assert.

ready

4 · Assertions & the coverage checklist

assert vs require, and the six cases every function needs.

ready

Part 2 — Mocks & mock generation available now

Test doubles, testify in practice, and the two generators behind mock/.

5 · Test doubles & why mock

Mocks vs stubs, and the port seam that makes a struct mockable.

ready

6 · testify/mock in practice

On/Return/Once, MatchedBy, AssertExpectationsForObjects.

ready

7 · Generating mocks

gen-mock, the two generators, the misleading header.

ready

8 · Mocking the database

mock_database.Ext/Tx and the testutil.MockDB toolkit.

ready

Part 3 — Testing the layers & running available now

A real test at each layer of spike, then running and coverage.

9 · Testing a usecase/handler

The flagship: inject mocks, mock the transaction, match entities.

ready

10 · Testing a repository

testutil.MockDB, faked scans, and SQL-shape assertions.

ready

11 · Testing a gRPC handler

Mock the usecase; cover every error path; fake the RBAC context.

ready

12 · Running, coverage & the workflow

unit-test-service, -count=3, the regen loop. Recap.

ready

Reference shelf

Cheat sheet

The test skeleton, testify recipes, DB mocking + interview one-liners.

Glossary

The canonical vocabulary, mapped to interview terms.

Repo testing map

Ground truth: rules, generators, mock/, spike's tests — with file:line.

Resources

go.dev, testify, mockery, Fowler — high-trust sources only.

All 12 lessons are built — the course is complete. You can now write a test that passes review — table-driven, mocked, error-paths covered, mocks regenerated — and read any test in the repo, naming what it does unusually (the two generators, the mockgen-header lie, testutil.MockDB's reflection scan, -count=3). The one thing left is a retention check — ask me to run a mock interview across the course (cold, no peeking) and I'll write the first learning records proving what stuck. Questions on any lesson? Ask me — that's what I'm here for.