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 2 of 6

The double decides what the test can see

A **test double** replaces a real dependency (network, database, clock) so a test runs fast and on its own. Its kind decides what the test can observe. The agent keeps working until the tests are green. That is a proxy signal: a visible stand-in for the real goal, which is correct code. The agent only ever sees what the double returns, never the real gateway. So a double that always answers "success" lets code that charges the wrong amount, or ignores a failed charge, pass. The later cost: a wrong charge or an ignored failure ships behind a green suite.
Terms on this card
test double
Any object a test puts in place of a real dependency, such as a stub, fake, mock or spy.
dependency
Something your code calls but doesn't own, such as a payment gateway, database, clock or another service.
green suite
A set of tests that all pass.
proxy signal
A visible stand-in for the real goal, such as tests going green, that can be satisfied without achieving the goal.
later cost
The concrete damage a shortcut does after merge, such as a hidden bug, corrupted data or a maintenance burden.
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