Watch · Hands-On Guide, Exercise 7

Testing as a Safety Net

2:32 · Hands-On Guide

Made by AI agents — script drafted from the book, AI narration, animation written as code — and steered by the author, Rasmus Bornhøft Schlünsen.

Transcript

What the film says

Your agent is coding blindfolded. Ask it for a sort button, and it writes the code, says done, and moves on. Did the sort work? Did it break the filter? Nobody checked. That's exercise seven: testing as a safety net.

Tests give the agent eyes. A test is a plain sentence about what your app should do, written so a machine can check it. Green means it works. Red means something's broken. And the agent can read that signal, just like you.

You start with Playwright. It opens your app in a real browser with no window, types, clicks, and checks the page. Your first test: add Tokyo, and a Tokyo card appears. Run it. One passed. One green line, in about two seconds. Then add three lines to the agent's instruction file: run the tests after every change, and never call a task done while they're red.

Next, build the suite. Describe each behaviour in plain English. Add a place. Refresh, and it's still there. Edit it, delete it, mark it as visited, filter the list. The agent writes a test for each. Before you run them, read them. A test that promises to refresh but never does will pass forever, and protect nothing.

Now flip it around. Ask for the test first: a sort button that puts the cards in alphabetical order. Run it. Red. Then tell the agent to make it pass, without touching the test, and check the diff to be sure. Green. Red, green, refactor. The test isn't just checking the work. It's the spec.

Then break something on purpose. Comment out the line that saves to local storage. The app still looks fine, until you refresh, and everything is gone. The tests go red. You only say: the tests are failing, fix it. The agent reads the failure, finds the line, and puts it back. Green again.

Last, automate it. A GitHub Actions workflow runs the whole suite on every push and every pull request. Push a broken branch, and the pull request gets a red X. Add a branch rule, and red can't be merged.

You stopped telling the agent only what to build, and started telling it what correct means. An agent that knows what correct looks like can check its own work. It isn't coding blindfolded anymore. Next up: exercise eight, the agentic pipeline.