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.
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.
2 · Table-driven tests & subtests
t.Run per case, t.Parallel, timeouts, and the loop-var pitfall.
3 · The house structure
newSuite + assertExpected + arrange/act/assert.
4 · Assertions & the coverage checklist
assert vs require, and the six cases every function needs.
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.
ready6 · testify/mock in practice
On/Return/Once, MatchedBy, AssertExpectationsForObjects.
7 · Generating mocks
gen-mock, the two generators, the misleading header.
8 · Mocking the database
mock_database.Ext/Tx and the testutil.MockDB toolkit.
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.
ready10 · Testing a repository
testutil.MockDB, faked scans, and SQL-shape assertions.
11 · Testing a gRPC handler
Mock the usecase; cover every error path; fake the RBAC context.
ready12 · Running, coverage & the workflow
unit-test-service, -count=3, the regen loop. Recap.
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.
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.