Capstone: Pila 1.2 · lesson 6 of 9
Ideas in this lesson
ATraceability6.5: each criterion → its test
BCharter6.7: explore … with … to discover …
CBug report6.8: steps, expected, actual
DRegression test6.9 and 8.P: fails before, passes after

Test

Last updated

You're the tester. The stories are built and their unit tests pass, but passing tests only show what someone thought to check. In this lesson you'll trace every acceptance criterion to a test, explore the feature for an hour with a charter, write up two bugs you find so that someone else could fix them, and fix them with regression tests that prove themselves.

By the end of this lesson you can

  • Check that every acceptance criterion has a test
  • Run a time-boxed exploratory session from a charter
  • Report two bugs clearly, and fix each with a regression test

Every criterion has a test

Go through your stories from C.2. For each acceptance criterion, find the test that checks it (lesson 6.5). Write the list in the pull request or in docs/stories.md:

The reference’s criteria, traced
CriterionTest
#50: vaccine due Tuesday, job runs Monday → one texttest_a_vaccine_due_tomorrow_is_reminded_today
#50: vaccine due Wednesday → no text yettest_a_vaccine_due_in_two_days_is_not_reminded_yet
#50: no names in the texttest_the_text_has_no_name_and_says_how_to_stop
#51: STOP stops reminders to that phonetest_stop_stops_reminders_to_that_phone_only
#51: STOP with none says sotest_stop_without_reminders_says_so
#52: deleted after 30 daystest_old_reminders_are_forgotten, at 30 and 31 days

A criterion with no test is a criterion nobody is checking. Write the missing ones now, before exploring.

Explore

Unit tests check what you expected. Exploratory testing (lesson 6.7) looks for what you didn't. Set a timer for an hour, write a charter, and explore your own feature as if someone else built it. Use the Python prompt, or a short script, with FakeGateway to see what would be sent:

Terminal
(.venv) $ python
>>> from datetime import date
>>> from pila.reminders import ReminderBook, send_due
>>> from pila.gateways import FakeGateway
>>> book = ReminderBook()
>>> book.add("0917 000 0000", "Pentavalent", date(2027, 3, 9), "San Roque")
>>> book.add("0917 000 0000", "Pentavalent", date(2027, 3, 9), "San Roque")
>>> g = FakeGateway()
>>> send_due(book, g, date(2027, 3, 8))
2
Exploratory sessionKept in this browser only
  • Explore … with … to discover … (not yet)
  • At least five things tried (not yet)
  • Notes something that surprised you (not yet)
Write each part until its checks pass.

Report what you found

Write up two bugs, from your session or from anything odd you noticed while building, so that someone who wasn't there could reproduce them (lesson 6.8). File each as an issue, labelled bug.

Bug reportsKept in this browser only
  • A specific title (not yet)
  • Numbered steps (not yet)
  • Expected (not yet)
  • Actual (not yet)
  • How much it matters (not yet)
  • A specific title (not yet)
  • Numbered steps (not yet)
  • Expected (not yet)
  • Actual (not yet)
Write each part until its checks pass.
Which is the more useful bug title?

Fix them, with regression tests

For each bug: a branch, then first a test that reproduces it and fails, then the fix that makes it pass (lessons 6.9 and 8.P). Run the whole suite, so the fix doesn't break anything else.

Terminal
(.venv) $ python -m pytest -q tests/test_reminders.py
.....F.....
FAILED tests/test_reminders.py::test_entering_the_same_reminder_twice_sends_one_text
    assert 2 == 1
1 failed, 10 passed
(.venv) $ python -m pytest -q
......................................             [100%]
38 passed

The first run is with the test and without the fix; the second, after the fix. Here's how the reference fixed both, in ReminderBook.add:

How the reference does it pila/reminders.py, lines 46–56
    def add(self, phone: str, vaccine: str, due: date, centre: str) -> Reminder:
        """Enter a reminder, after the mother has agreed at the counter.

        Agreeing again at the counter starts reminders again after a STOP (#61),
        and entering the same reminder twice keeps one (#60).
        """
        reminder = Reminder(normalise(phone), vaccine, due, centre)
        self.stopped.discard(reminder.phone)
        if reminder not in self.reminders:
            self.reminders.append(reminder)
        return reminder

Each fix's pull request says “Closes” its bug's issue, as before.

Check your testing

Why write the regression test before the fix?
All the unit tests passed, and exploring still found two bugs. Why?

Sources

Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.

All sources for Simple Software Development