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:
| Criterion | Test |
|---|---|
| #50: vaccine due Tuesday, job runs Monday → one text | test_a_vaccine_due_tomorrow_is_reminded_today |
| #50: vaccine due Wednesday → no text yet | test_a_vaccine_due_in_two_days_is_not_reminded_yet |
| #50: no names in the text | test_the_text_has_no_name_and_says_how_to_stop |
| #51: STOP stops reminders to that phone | test_stop_stops_reminders_to_that_phone_only |
| #51: STOP with none says so | test_stop_without_reminders_says_so |
| #52: deleted after 30 days | test_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:
(.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
- Explore … with … to discover … (not yet)
- At least five things tried (not yet)
- Notes something that surprised you (not yet)
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.
- 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)
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.
(.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:
pila/reminders.py, lines 46–56def 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
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.
- pytest documentation: Get started: running tests, and reading failures
- James Bach: Exploratory Testing Explained: charters and time-boxed sessions
- ISTQB Glossary: definitions of exploratory testing, regression testing and defect report
- GitHub Docs: About issues: bug reports as issues