Summary: Isolate a defect by starting with a system-level test. Progressively inline and prune until you have the smallest possible test that demonstr

Software Design: Tidy First?

submited by
Style Pass
2024-04-30 18:00:08

Summary: Isolate a defect by starting with a system-level test. Progressively inline and prune until you have the smallest possible test that demonstrates the defect.

In American football there is a play called “The Sandwich” in which two people hit the person carrying the ball simultaneously, one up near his shoulders and the other near his waist. Sandwiching is definitely not done out of concern for the ball carrier’s health.

A recent bug in JUnit put me in mind of The Sandwich. We had just gotten JUnitMax (about which more later) to the dog food stage, but it ran some tests repeatedly. What was going on?

Running this test showed that four tests were being run, not two. (The first version of the test ran JUnit 4-style tests and it passed, leading to a minute or two of head scratching.) The test above hits the defect high, from the point of view of a user. Here’s where the Saff Squeeze came in.

Just because I have a failing test, though, doesn’t mean I know how to fix the defect. If I can write the narrowest possible test that still fails, I will have isolated the code that needs to change [ed: see also the Test Desiderata, in particular the property that tests are more valuable when they are Specific]. Finding the problematic logic will help me prepare to fix it. Finally, the resulting test will help ensure that the defect is fixed and stays fixed.

Leave a Comment