Course outline · 0% complete

0/29 lessons0%

Course overview →

Capstone Part 2: Fix Every Bug

lesson 10-2 · ~13 min · 29/29

Now make it green

The starter below is the module plus your full five-test suite from part 1, still reporting 2/5 passed. Fix the module, not the tests, they encode the spec. Work like the professional this course built:

  1. pick ONE failing test
  2. hypothesize the cause (the exception bestiary and boundary analysis have already done most of the thinking)
  3. change one thing in the module, rerun, watch that test flip green
  4. repeat until 5/5 passed

If a fix turns something else red, the safety net from lesson 1-2 just earned its keep. All three bugs are single-line fixes.

pick ONEfailing testfix one linein the modulererun ALL fivewatch for regressionsrepeat until the report reads 5/5 passed
The capstone fixing loop: one failing test, one change, full rerun, until everything is green.

Code exercise · python

Fix the three bugs in new_wallet/deposit/withdraw, one at a time, without touching the tests, until the report reads 5/5 passed.

Quiz

Six months later someone refactors wallet to store cents as integers. What do your five capstone tests do for that person?

Problem

Final check, one word. You fixed withdraw's >= to >, and before shipping you rerun ALL five tests, not just the one that was red. The course habit you are applying is checking for what kind of accidental breakage, where a change breaks something that used to work?

Where this goes next

The habits are the point, not the toy runner. In real projects you will write these same tests with pytest, the standard Python test tool: every test_ function you wrote here works there almost unchanged, assert and all, and pytest supplies the reporting, filtering, and table-driven conveniences you built by hand in lessons 1-3 and 3-3. Your suite will run automatically in continuous integration (lesson 6-3) on every change you propose, guarding teammates you will never meet. And the debugging loop — reproduce, minimize, hypothesize, bisect, prove the fix with a test — is identical whether the code is ten lines or ten million. Test first, trust green, change fearlessly.