A philosophical and practical argument for treating mocks as first-class participants in tests rather than disposable stubs. The author distinguishes between mocks (nouns — contract-enforcing collaborators) and stubs (canned-response fakes), arguing that mocks should act as protagonists that drive the testing narrative. Using Elixir's OTP and the Finitomata FSM library as a case study, the post demonstrates how mock-as-listener patterns eliminate race conditions in async tests by replacing Process.sleep with deterministic assert_receive synchronization. The Finitomata.ExUnit module is presented as a concrete implementation of this philosophy using Mox.
Table of contents
Mock Is a NounStubs Are for Candles, Not for SoftwarePromote Your Mocks to Lead ActorsOTP, Race Conditions, and the Debugger You DeserveListeners, Visibility, and the Joy of Seeing What HappensFinitomata: A Case Study in Mock-Driven TestingThe MoralSort: