Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Test doubles: stubs, fakes, mocks and spies card 3 of 6

Four kinds: what each checks and skips

- **Stub**: returns canned answers. Checks your code's output given that answer. Skips how your code called the dependency, and how the real one would answer. - **Fake**: a working lightweight version, such as an in-memory store. Checks behaviour across many calls, with real state. Skips wherever it differs from the real thing. - **Mock**: set up with expected calls, and fails if they don't happen. Checks interactions. Skips what your code does with the answer, unless the test also asserts on output. - **Spy**: records calls so you can assert on them afterwards. Checks only the calls you assert on. Skips every call and argument you don't.
Terms on this card
stub
A test double that returns canned answers and checks nothing about how it was called.
fake
A test double that is a working but simplified implementation, such as an in-memory store, which keeps real state between calls.
mock
A test double set up with expected calls that makes the test fail if those calls don't happen.
spy
A test double that records the calls made to it so the test can assert on them afterwards.
dependency
Something your code calls but doesn't own, such as a payment gateway, database, clock or another service.
Learn this step by step on Bytewise
Lesson goal: Distinguish the four kinds of test double: stubs return canned answers, fakes are working lightweight implementations, mocks verify interactions and spies record calls. Say what each kind lets a test verify, and what it lets a test silently skip. · the whole lesson