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.
Mocks that test nothing
card 6 of 6
Remember
builds on: Test doubles: stubs, fakes, mocks and spies, What makes a test able to fail
Some tests cannot go red when the logic is wrong. Watch for three kinds: tests that mock the code they test, tests that assert a mock's own canned value, and tests that only count calls. To fix one, run the real unit, fake only what sits at its edges, and assert the result the spec demands.
Terms on this card
- mock
- A test double that is preconfigured with answers and checks which calls it received.
- fake
- A working, lightweight implementation of a dependency, such as an in-memory store in place of a database.
- spec
- Short for specification: the stated rule the code must follow, and the source of a test's expected values.
- red
- A test or check that is failing. Green means passing.
Lesson goal: Recognise tests that mock the unit under test, assert that a mock returned what it was configured to return, or check only that calls happened without checking any outcome. Rewrite such a test to exercise real logic, using fakes where possible. ·
the whole lesson