Testing Ticket Reopening
Introduction
Welcome back to Review for Code Health. We have completed three lessons on reviewing design, tracing behavior, and challenging unnecessary complexity. In this fourth lesson, we will turn our attention to tests as part of production code: a test should make a behavior clear and catch a change that breaks it. We will review a ticket reopening proposal, write a focused finding, and check the author’s revision before deciding whether the feature is ready to approve.
Read the Requirement and the Initial Proposal
We begin with the requirement in INITIAL_DIFF.md: reopening a closed ticket must change its status to "open". The initial proposal calls reopen(), but its assertion checks something different: whether the ticket object exists. As in earlier lessons, we compare the proposed evidence with the behavior the requirement promises.
The ticket is created before reopen() is called. Therefore, this test needs to establish more than the existence of a ticket: it needs to show that a closed ticket becomes open. Let’s trace why the proposed assertion does not do that.
Spot a Test That Can Pass While the Feature Is Broken
The create_ticket function returns a ticket object. The proposal stores that object in ticket, calls reopen(), and checks that ticket is not None. Because the object already exists, the check can pass even if reopen() does nothing.
A useful review question is: Would this assertion fail if the new behavior were missing? Here, the answer is no. That makes the test weak evidence for the requirement, even if it passes every time it runs. We need an assertion that observes the ticket’s status after reopening.
Compare the Weak Test with Failure-Sensitive Evidence
A more meaningful test creates a clear starting condition, performs the action, and checks the visible result. For reopening, that means three things: start from a ticket that is actually closed, call reopen(), then check the status the requirement promises.
To see why this matters, compare two kinds of assertion against two versions of reopen():
- An existence check (
assert ticket is not None) passes whenreopen()works, and it still passes whenreopen()does nothing. - A status check after closing and reopening the ticket passes when
reopen()works, and it fails whenreopen()does nothing.
Only the second kind can tell a working feature from a broken one. That difference is the concrete behavioral evidence we will ask the author to provide.
