dev-tools
Glossary ↗Mocking (Test Doubles)
Mocking is the practice of replacing a real dependency in a test with a controllable stand-in — a "test double" — so you can test one piece of code in isolation without invoking slow, unreliable, or expensive external systems. Instead of calling a real payment gateway or database in a unit test, you swap in a mock that returns predetermined responses and lets you assert how it was called. This makes tests fast, deterministic, and able to simulate hard-to-reproduce cases like a network timeout or a 500 error. Mocks, stubs, fakes, and spies are all flavors of test doubles with slightly different jobs. For AI/SaaS builders, mocking is how you unit-test code that talks to third-party APIs — Stripe, an LLM provider, an email service — without hitting them on every run. Practical note: don't over-mock. If you mock everything, your tests verify your assumptions about a dependency rather than reality, so keep some end-to-end tests that exercise the real integrations too.
Related terms