Turn a Bug into a Regression Test
Scenario
The old condition freeSeats >= 0 allowed a booking in a full room.
- 1…
- 2…
- 3…
Try it yourself
Order the steps that prove the test catches the bug and the fix corrects it.
Reveal the explanation
- Add a check that canBook(0) is false
The expected behavior is captured.
- Run it against the buggy implementation
The test fails for the known reason.
- 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.
This browser could not save your progress. Changes last until you leave the page.