Mocking lets a test control responses from dependencies such as a network API or payment service. It makes success and failure cases quick to reproduce.
The demo switches an app’s connection from a service to a stand-in response. A mock can drift from the real contract, so integration tests should cover that boundary too.
When to use
Use it to reproduce external failures, latency, or rare responses reliably.