Introduction
Mocking helps test one part of code by pretending other parts work correctly. This way, you focus only on what you want to check.
When a function depends on a slow database or network call.
When a part of code uses an external service you cannot control.
When you want to test error handling without causing real errors.
When the real code changes data and you want to avoid side effects.
When you want to test a small piece of code without running the whole system.