XUnit Test Patterns and Smells; Improving Test Code Through Refactoring
XUnit is the generic name given to the family of tools/frameworks used by developers when developing automated unit tests. JUnit, NUnit, MsTest and CppUnit are some of the better known members of the family. High quality automated unit tests are one of the key development practices that enable incremental development and delivery of software. This tutorial provides the participants with a vocabulary of smells and patterns with which to reason about the quality of their test code and a set of reusable test code design patterns that can be used to eliminate the smells.
The tutorial is presentation based frequently punctuated with short (5 minute) hands-on exercises that help the participants “experience” the smells and patterns. The material is presented as a sequence of mini case studies. Each case study starts with a sample of test code or test results and we discuss the “test smells” present in the tests and their impact on achieving our goal of repeatable, robust, fully-automated tests. Then we dig into the root causes of the smell(s) and present a set of alternative patterns that can be used to address them.
Exercises will be done in small groups. Ideally, participants will be able to form into groups of 3-4 to discuss the smells, causes and patterns in each exercise.
This tutorial was one of the sessions picked for repeating in the final timeslot of Agile 2008.
- Participants will learn:
- • The difference between well-written automated unit tests and poorly written ones
- • To recognize common code smells that make test code hard to understand and maintain.
- • Recognize common behavior smells that increase the cost of running tests and interpreting the test results
- • Test design patterns to avoid the behavior smells and which lead to highly repeatable and robust tests.
- • Test coding idioms that make tests easier to understand and less fragile.

Download session PDF
Add to calendar