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.
Part 4 — Senior testing practice new
The senior stretch — strategy, seam design, flake triage, double selection, test review judgment, and interview-grade answers.
13 · Testing strategy & the pyramid
Choose the cheapest reliable layer for the bug you want to catch.
new14 · Designing testable code & seams
Why good seams make honest tests easier and reveal decomposition quality.
new15 · Flaky tests & triage
Shared state, timing, ordering, and what repeated runs are really trying to expose.
new16 · Choosing doubles
Pick between mocks, `MockDB`, and heavier collaborators intentionally.
new17 · Reviewing tests
Judge signal, brittleness, and false confidence like a senior reviewer.
new18 · Senior interview questions
High-signal testing questions with the right answer shape.
new19 · Mock senior interview pack
A retrieval-first mock round with scoring and strong answer points.
newReference 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 — plus senior testing topics.
Senior backend playbook
The compressed version of the new senior part: strategy, seam design, flake triage, double choice, test review, and interview answers.
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.