Mocking Functions and Modules
Replacing real dependencies with controlled fake implementations during tests to isolate the code under test and verify how it interacts with its dependencies.
Mocking replaces a real dependency — a function, a module, an API client — with a controlled, fake implementation during a test, letting you isolate the specific code you're actually testing from the behavior (and side effects, and slowness, and flakiness) of everything it depends on. This is essential for genuine unit testing, since a 'unit' test that actually reaches out to a real network or database on every run is slow, flaky, and no longer testing just the unit in isolation.
Mocking is like rehearsing a play with a stand-in prop gun instead of a real one — the actor still practices exactly the same motions and cues (the interaction/call pattern being verified) without any of the real risk, cost, or unpredictability a live prop would introduce, and the director can specifically check whether the actor pulled the trigger at the right moment, regardless of what a real gun would have actually done.