Skip to content
>devspeak
← glossary
level 6Testing & Reliability

Mock

also: mocks, mocked, mocking, mock object

A fake stand-in a test uses in place of a real part, like a pretend payment service, so the test runs fast and doesn't touch the real thing.

a bit more technical

A test double that replaces a real dependency, such as an API client, database or clock, with a controlled fake. Mocks return preset answers and can record how they were called. They isolate your code, but they only behave the way you told them to.

picture it

A flight simulator. Pilots practice safely without a real plane. But if the simulator handles differently from the real plane, the practice proves less than it seems.

why it matters

Mocks are useful, but agents sometimes mock away the very thing that's broken. A test that fakes the database can't catch a database bug. When a test passes, ask what was real and what was faked.

what your agent might say
agent
I mocked the Stripe client so the tests don't make real network calls. The mock returns a successful payment for every request.
how you might use it
you → your agent
Mock the external weather API in the unit tests, but keep one integration test that uses our real test database. List everything you mocked.
common mistake

Confusing a mock with a fixture. A mock fakes a part of the system; a fixture is prepared starting data or setup, like three sample users.

builds on