Identify and Exploit Behavioral Boundaries for Unit Testing
Whether writing unit tests after coding or using test-driven development (TDD), developers often ask themselves—How much testing is enough? Or too much? Or not enough? Rob Myers helps answer these questions using the techniques from his experience doing and teaching TDD. Look for those tests that cause us to write code, look for unique behaviors and code-paths, and strive to narrow in the boundary conditions. This gives us pinpoint accuracy when something breaks. Rob demonstrates what this approach looks like using graphs, tests, and code. To answer “What needs to be tested?” Rob introduces the Hungover Intern Principle—write the tests that will defend our code’s behaviors against any mistakes during later refactoring or optimization, whether the mistakes are made by an earnest but inexperienced intern or by us. Rob shows how to do this without introducing duplicate tests.