Patterns

6 posts tagged “Patterns”. All posts →

Contract Testing Go Interfaces with Generic Test Suites

Go interface contract testing with generics: define the contract in one test suite, instantiate it for every implementation, and catch drift as it happens.

Snapshot Testing in Go

Snapshot testing in Go without boilerplate: gotest.MatchSnapshot stores golden files, diffs on mismatch, works in parallel tests, and is read-only in CI.

Testing Async Code in Go Without time.Sleep

Go async tests without time.Sleep: Eventually and Consistently separate how long to wait from how often to check, so tests stay fast and stop flaking.

Go Test Lifecycle: Setup, Teardown, and Execution Order

Go test setup and teardown, in order: suite hooks, fixture hooks, cleanup guarantees, and retries — the full gotest lifecycle from BeforeAll to AfterAll.

Test Fixtures in Go: Patterns That Scale

Every growing Go project needs shared test infrastructure. Fixture patterns from global vars to DAG-based lifecycle management, and when to use each.

Organizing Go Tests Beyond func TestX

Why flat Go test functions, table-driven tests, and subtests each solve part of the organization problem — and what happens when you need all three at once.