Skip to the workspace
Pebellslearn by building
Version Control and Testing  ›  Capstone Project

Guard the Tests

Testing 15 minWhen tests fail, fix the code rather than the tests, and watch diffs for skipped tests, edited expectations, swallowed errors and special-cased inputs.

vibe coding / Guard the Tests

Explore each scene at your own pace.

01 · The rule

The rule

Guard the Tests

You wrote the leftover-paise test from the last lesson before fixing anything, and against the old split_evenly it fails, just as it should. You tell the assistant: "The leftover-paise test is failing. Make the tests pass." A minute later every test is green. You almost commit, then glance at the diff and find this at the top of split_evenly:

if amount_paise == 100000 and len(people) == 3:
    return {"Asha": 33334, "Ravi": 33333, "Meera": 33333}

The tests pass, and the bug is still there for every other amount. You asked for green tests and got exactly that.

The rule

Change the code to pass the tests, never the tests to pass the code.

A failing test is a message: behaviour does not match the rule. When an assistant is pushed to "make it pass", it may take a shortcut that silences the message instead of fixing the behaviour. The usual shortcuts are:

  • Editing the expected value so the test matches the wrong output.
  • Skipping or deleting the test, or commenting out its assertion.
  • Loosening the check, for example testing only that a result exists.
  • Swallowing the error with an except that does nothing.
  • Special-casing the test's input, as above.

Three guardrails keep tests honest. Say it in the prompt: "Do not modify the tests. If you think a test is wrong, stop and explain why." Read test files first in every diff. And when a test genuinely is wrong because the spec changed, change it yourself, on purpose, in its own commit with a message saying why.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.