Skip to content

Fixture vs stub vs mock

A fixture prepares the world, a stub answers a call, a mock asserts that a call happened; they solve three different problems.

Aspect

Fixture

Stub

Mock

What it prepares

The environment and data

A canned answer

An expectation

When it acts

Before and after the test

During the call

During and after

Fails the test?

Only if setup throws

No

Yes, on unmet expectation

Typical example

A database seeded with three users

A clock that always returns noon

A payment gateway that must be charged once