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

BETTER: real logic, fake at the edge

builds on: Test doubles: stubs, fakes, mocks and spies, What makes a test able to fail
Keep the real `Checkout`. Replace only the edge it talks to, storage, with a fake: `FakeRepo` really stores carts. The expected values come from the rule, including the edge case of exactly 100. Break the rule in `total` and at least one test goes red. 20 off gives 100, not 110. A discount at exactly 100 gives 90, not 100. Check calls only when the call *is* the outcome, such as an email being sent. Even then, check the call's arguments.
// Python  BETTER
class FakeRepo:
    def __init__(self, carts):
        self.carts = carts
    def cart(self, user):
        return self.carts[user]

def test_10_off_over_100():
    repo = FakeRepo({"u1": [70, 50]})
    assert Checkout(repo).total("u1") == 110

def test_no_discount_at_100():
    repo = FakeRepo({"u1": [50, 50]})
    assert Checkout(repo).total("u1") == 100
Terms on this card
fake
A working, lightweight implementation of a dependency, such as an in-memory store in place of a database.
red
A test or check that is failing. Green means passing.
Learn this step by step on Bytewise
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