Mock
vs Stub
Stub
Provides pre-defined responses to method calls and is usually used to control the environment of the test. It helps you verify if the system behaves correctly based on the return values it produces.
Mock
Simulates behavior and also allows you to verify interactions with the dependencies.
In addition to providing responses, it records and asserts that certain methods were called with specific arguments.
mock
Mock
is about controlling a behavior.
mock
The argument usually revolves around avoiding excessive coupling between your tests and your code.
If you are asserting things like how a particular interface was called, what arguments it was called with, how many times it was called etc, this is asserting the implementation details, which is almost never (but not never never) desired.
You usually only want to test the end behavior, which is why integration testing is the more useful kind of test.
However, testing a full integration suite is sometimes impractical. You might need to integrate with dozens of systems.