Verified Jobs Live
Testing Medium Level ~3 min read

When do mocks make tests weaker rather than stronger?

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

Mocks weaken confidence when they reproduce implementation details, assume undocumented dependency behavior, or allow interactions that the real dependency would reject. A test can pass while serialization, SQL constraints, or network error handling is broken. Mock narrow exte al boundaries when needed for determinism and speed, but use suitable integration or contract tests for important real interactions. Assert meaningful outcomes rather than every inte al method call. If routine refactoring breaks many tests without changing behavior, the tests may be coupled too closely to the implementation.