Design Patterns · Middle · Question 39 of 75

How does a mock differ from a stub in tests?

Explanation

Test doubles: dummy (a placeholder), stub (canned answers), spy (records calls), mock (with expectations about calls), fake (a simplified working implementation, e.g. an in-memory repository). Dependency injection makes substitution easy.

Further reading

Problem with a question

Design Patterns · Middle · question 39

Test yourself

Take the Design Patterns · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz