Part 2. Catalog

 

The goal of part 2 is to help us better identify and fix problems with our test code, and we’re taking a “catalog”-style approach to accomplishing that. This catalog is one of test smells—traits and attributes we often encounter in test code that create or aggravate problems in terms of maintainability, readability, and trustworthiness.

We are wallowing in this puddle of anti-patterns instead of walking through a list of good practices because I’ve found it more effective to teach programmers to identify problems with their tests and to rectify them. After all, if we only know what a good test looks like, we’re still blind to the many flaws our code may have.

My good friend Bas Vodde likes to say that if you remove all the test smells you can identify, what’s left is likely to be a pretty good test. Besides, the design principles and guidelines for good code are just as valid for test code as they are for production code—which means we already have a body of knowledge to refer to in determining what kind of properties our test code should exhibit.

Our catalog of test smells is divided into three chapters, each collecting a group of test smells around a theme. Chapter 4 presents smells that suggest issues with the readability of our tests. Chapter 5 continues with advice on keeping our tests from becoming a maintenance issue. Chapter 6 concludes this part with a set of test smells that often correlate with flaky or otherwise unreliable tests.