Mocking in Go: Using interfaces for fun and profits
summary
A small mailing system called gomez mailing server gets implemented as an interface so each component is testable in isolation. Mocking is concrete: a mock structure with matching signatures provides replaceable method fields and lets tests assert that q1 mailbox is called and parameters propagate. To hit error branches the approach injects failures for SplitHostPort and for reverse lookups. Networking either uses a handcrafted mock net.Conn with fake LocalAddr/RemoteAddr or falls back to net.Pipe limitation. This is driven by coverage-driven error injection.
AI-written summary · about
chapters (3)
related talks
48mClimbing the Testing Pyramid: From Real Service to Interface Mocks in Go
50mThe Best Mock in the World: Examining Tools for Generating Mocks in Go
07mHow to Mock Fellow Gophers While Avoiding HR
50mThe best mock in the world: examining mock generation tools in Go
28mMocking with Swift
20mHow to Mock in the 21st Century
31mBeyond the Mockery- Why We Should Embrace Testing Without Mocking Frameworks
33mMock Me If You Can: Using Mocks in Container Applications for Integration Testing
