Design Patterns · Middle · Question 39 of 75
How does a mock differ from a stub in tests?
- ✓Correct answer: A stub returns canned data, a mock also verifies calls
- 2A mock returns canned data, while a stub verifies calls
- 3They're synonyms; the difference is only in library names
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.