Get your API key

Lesson 5 of 5

Tests before and after every change

The red, fix, green, commit loop, an AGENTS.md testing rule, asking for evidence, and spotting an AI that deletes or skips tests.

8 min Log in to open
One step at a time, like flipping pages.

By the end of this lesson every change your agent makes will follow one loop: tests before, one change, tests after, commit only when green. Your rules file will enforce it, and you will spot an agent that cheats on tests.

You need: your project with unit tests (Lesson 3) and end-to-end tests (Lesson 4), Git save points (Never lose your work), your coding agent · Time: 8 minutes

  1. Tests only protect you if they run every time. Use the same loop for every feature and every fix, however small:

    1. Tests before: run them. All green means you start from a safe place.
    2. One change: the agent adds one small feature or one fix.
    3. Tests after: run them again, and paste the output.
    4. Red? Fix the code, never the test, and run again. Green? Commit a save point.
    A loop diagram. 1 Tests before: npm test, all green means a safe start. 2 One change: the AI adds one small feature or fix. 3 Tests after: npm test again, paste the output. If a test fails, go to Red: fix the code, never the test, then run tests again. If all pass, go to 4 Green: commit a save point you can come back to. A dashed arrow from commit goes back to step 1 for the next change. A yellow note says the number of tests never goes down.
    Before, change, after, commit. Red means fix the code; green means save.
    Why?

    If tests were already red before the change, you cannot tell which failures are new. If you change five things at once, you cannot tell which one broke the test. The loop keeps both questions easy.

Log in free to read the rest of this lesson

Every lesson is free. A free account unlocks all of them and saves your progress.

Still to come in this lesson:

  1. Put the rule in AGENTS.md
  2. Ask for evidence, not promises
  3. Spot an agent that cheats
  4. Every bug becomes a test
  5. Recap