All jobs / Backend developer / Testing

Backend developer interview question · 0–1 years

In a test, what is the difference between a stub, a mock and a fake?

The strongest answer

A stub returns canned answers so the code under test can run; a mock also records calls so the test can assert an interaction happened; a fake is a real but lightweight implementation, such as an in-memory repository

Why it works

Right — and the practical point is that asserting on a mock ties the test to how the code works, not to what it does.

What a good answer covers

Answers that fall short

Who gets asked this

More Testing questions