Chapter 5. Maintainability

 

In this chapter

  • Test smells that add to your cognitive load
  • Test smells that make for a maintenance nightmare
  • Test smells that cause erratic failures

In this second chapter of part 2 we turn our attention from the readability of test code toward its maintainability.

Many of us have heard the quip that code is read much more often than it’s written. That was the case with punch cards and it’s still the case today. That is why readability is so crucially important. When we go beyond merely looking at code, we step into the world of writing code—and most often “writing” really means modifying or extending an existing code base. Sometimes we call that maintenance and sometimes we call it development. In any case, something probably needs to be changed about the code.

What makes code such a fascinating medium to work with and programming such a difficult skill to master is that the nature of code is to be both extremely flexible and extremely fragile. Code is flexible because there are few things that can’t be done with software—it’s without physical constraints. It’s fragile because even the smallest of changes can break it down completely. Code doesn’t degrade slowly. It crashes.

5.1. Duplication

5.2. Conditional logic

5.3. Flaky test

5.4. Crippling file path

5.5. Persistent temp files

5.6. Sleeping snail

5.7. Pixel perfection

5.8. Parameterized mess

5.9. Lack of cohesion in methods