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.
Tests that restate the implementation
card 3 of 6
Three tells of a test that can't fail
builds on: What makes a test able to fail
- **Mirrored oracle:** expected value computed with the code's own formula, constant or helper. A wrong formula is wrong on both sides.
- **Frozen snapshot:** snapshot or golden file recorded from current output and never checked against the spec. It stores the bug as truth.
- **Weak assertion:** `is not None`, `assertNotNull`, `assertDoesNotThrow`, `toBeDefined()`, or Go `err == nil` with no check on the value. Any wrong value passes.
Check: if the logic had been wrong from the start, could this test go red? An expected value copied or recorded from the code can't.
Terms on this card
- oracle
- The expected result a test compares against. To be useful it must come from the specification, not from the code being tested.
- spec
- Specification: the stated rules for what the code should do, such as a requirements document or ticket, independent of how the code is written.
- snapshot
- Stored output from an earlier run. Later runs compare against it, and the test fails if the output differs.
- golden file
- A file holding the expected output that a test compares against; often generated by running the code once.
- mirrored oracle
- An expected value computed with the same formula, constant or helper as the code under test, so it is wrong whenever the code is.
Lesson goal: Spot tests whose expected value is computed with the same formula as the code, snapshots that freeze current buggy output, and assertions that check only 'not null' or 'no exception thrown'. Explain why these stay green when the logic is wrong. ·
the whole lesson