Skip to content

FAQ

Frequent questions about stubs: how they differ from mocks, when they are enough, and how they relate to fakes.

Is a stub the same as a mock?

No. A stub returns a fixed answer and does not check whether it was called. A mock does check, and fails the test if the expectation is not met.

Is a fake a stub?

A fake has working logic, usually a simpler implementation (an in-memory database). A stub has no logic, only canned answers.

Can a stub fail a test?

Only if the stub itself throws. It does not fail on unmet expectations, because it has none.

When is a stub enough?

When the test only needs a dependency to return something plausible so the unit can continue.