Skip to content

Mock vs stub: the 2007 line

Martin Fowler's 2007 article drew the sharpest line: stubs use state verification, mocks use behaviour verification.

Aspect

Stub

Mock

What it checks

The state left after the call

The calls made during the test

Verification style

State verification

Behaviour verification

Fails on unmet expectation

No

Yes

Coupling to implementation

Low

High

Best for

Isolating a dependency

Asserting a collaboration

Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

— Martin Fowler, *Mocks Aren't Stubs*, 2 January 2007