Mocking
Noun ยท Verb · Development
Definitions
Mocking is a testing technique where fake objects or functions stand in for real dependencies, allowing code to be tested in isolation without hitting databases, network services, file systems, or other external resources. A mock simulates the behavior of a real component, returning predefined responses and optionally recording how it was called. Related concepts include stubs (which return fixed data but do not verify interactions), fakes (simplified working implementations), and spies (which wrap real objects to record calls). Libraries like Mockito (Java), unittest.mock (Python), and Sinon (JavaScript) make it easy to create mocks. Overusing mocks can lead to brittle tests that pass even when real integrations break, so teams balance mocking with integration tests.
In plain English: Using fake stand-ins for real services during testing so you can check your code works without actually calling external systems.
Example: "Mock the payment gateway unless you want your test suite to charge your credit card a thousand times."