Vibe Coder · Unit 13: Testing and Security · Lesson 5 of 11

Automated tests

Engineers: unit, integration and end-to-end tests written with an agent, and how to make sure they test something real.

Read the short notes and pictures.Do everything inside a blue frame.

Tests that run themselves

Automated tests turn your test plan into code that runs on every change. Agents are good at writing them, and prone to writing ones that assert little. The discipline is to confirm each test fails for the right reason.

A 3D scene of coloured blocks and cards. Three kinds: unit, integration, end-to-end.
Unit, integration and end-to-end.

What to automate first

The main path, end to end

Sign up, do the one job, see the result.

Access rules

User A cannot read user B’s rows.

Money and maths

Any calculation.

The AI route

With a mocked model client.

A 3D scene of coloured blocks and cards. : A real test, A hollow test.
A real test fails when the code breaks.

Working with an agent

  1. Write the test first

    From the "done" sentence.

  2. Watch it fail

    Before the code exists or with the code broken.

  3. Implement until it passes

    Without editing the test.

  4. Forbid weakening

    A rule in CLAUDE.md: never change a test to make it pass.

ActivityBuild stepA tested, locked-down app

Automate your main path

Add an end-to-end test for the main path, an integration test for RLS, and unit tests for your calculations. Prove each can fail, and run them in CI.

Done when

Your test plan now runs on every pull request.

Keep these

  • Automate the main path, access rules and maths.
  • Make every test fail once.
  • Run them in CI.