Curriculum

Curriculum

Turn a Bug into a Regression Test

Scenario

The old condition freeSeats >= 0 allowed a booking in a full room.

  1. 1…
  2. 2…
  3. 3…

Try it yourself

Order the steps that prove the test catches the bug and the fix corrects it.

Reveal the explanation
  1. Add a check that canBook(0) is false

    The expected behavior is captured.

  2. Run it against the buggy implementation

    The test fails for the known reason.

  3. Fix the comparison and rerun the tests

    The zero-seat check passes. Keep it in the suite.

If the test passes on the buggy version, inspect what it calls and what it actually asserts.

Your turn

Run the zero-seat check on the faulty version, then rerun it after the fix.

Common mistake Writing a test that already passes on the faulty version.

Check your work

The same check fails before and passes after, with the same expected output.