DEV Community

Cover image for The Saff Squeeze
Jan Van Ryswyck
Jan Van Ryswyck

Posted on • Originally published at principal-it.eu on

The Saff Squeeze

From time to time, we encounter bugs in the software systems that we work on. That’s part of the life as a software developer. Often, we don’t know the root cause of the defect. So, in order to uncover what is going on we typically start a debugging session.

However, when we take a step back and think about defects from a higher level, we can conclude that every bug in the system actually corresponds to a missing test in the code base. An alternative to this default behavior is using the Saff Squeeze technique. The goal of this technique is to find that missing test.

The Saff Squeeze is a way to find bugs, starting with a high-level end-to-end test and working towards a small, unambiguous test that clearly demonstrates the defect.

“ Inline parts of a failing test until the reason for the failure becomes obvious.

— J.B. Rainsberger

The technique works by following these steps:

  1. Start with a failing high-level test that reproduces the defect.
  2. Inline the method(s) called on the system under test. (Breaking encapsulation is acceptable at this stage)
  3. Add assertions at the beginning of the test, gradually moving towards the failure while verifying all assumptions.
  4. Tidy up the test code and remove all irrelevant parts.
  5. Repeat until the test is minimal and the defect becomes obvious.

Some advantages of using this technique:

  • Leaves behind clear, reusable unit tests.
  • Turn defects into focused insights.
  • Encourages debugging through testing rather than relying on breakpoints or stepping through code.
  • Allows a steady pace from failure to fix.

Just give it a try. It’s a useful way to find defects while adding missing tests to your codebase.

References:

Top comments (0)