Skip to content

What it is

A mock is a test double that records calls and asserts expectations, failing the test when the expected interactions do not happen.

A mock is a test double with a contract. You tell it, before the test runs, which methods will be called, with which arguments, and how many times. When the test ends, the mock checks the ledger. If the ledger does not match the contract, the test fails.

That is the whole difference from a stub. A stub only answers. A mock answers and judges.