Stage 3 · Build
Production-Ready Services
Service Testing
Combine httptest, Testcontainers, contract tests, race detection, and CI database fixtures.
Testing Pyramid
The testing pyramid has many fast unit tests at the base, fewer integration tests in the middle, and a small number of end-to-end tests at the top. Focus on unit and integration tests for the best return on investment.
| Type | Speed | Coverage | Cost |
|---|---|---|---|
| Unit | Fast (ms) | Individual functions | Low |
| Integration | Medium (s) | Component interactions | Medium |
| E2E | Slow (min) | Full system | High |
httptest
Testcontainers
Contract Tests
Race Detection
# Run with race detector
go test -race ./...
# Run integration tests separately
go test -race -tags=integration ./...
# In CI
go test -race -count=1 -timeout 300s ./...The race detector finds concurrent access to shared variables without synchronization. It catches data races that cause intermittent test failures and production bugs.
CI Database Fixtures
Always run go test -race in CI. The race detector catches data races that are nearly impossible to reproduce locally. It adds ~10x overhead but catches critical bugs.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.