11 Data Oriented Testing
This chapter covers
- The testability of data-oriented code
- Writing data-oriented tests
- Working with randomized test data
This chapter will teach you how to write good tests. We’ll learn how to exploit the inherent testability of data-oriented code to create tests that are small, simple, and clear. We’ll also learn how to use data to improve legacy tests and code. Representation remains the essence of programming even in tests. Small changes have outsized impacts on understandability.
Once we can write good tests, we’re going to learn how to write great ones. The remainder of the chapter is devoted to the art and craft of generating randomized test data. It is the most powerful technique I know for creating tests that can actually prove something about a program (or at least make us very confident). The technique is unwieldy and strange at first and requires shifting how we think about the role of software testing, but the reward is a suite that can catch and prevent errors before they reach our users.
11.1 A few definitions
Every developer describes testing differently. What one calls an “Integration test,” another might call a an “acceptance” test, or maybe a “behavioral” or “end-to-end” test. Even the “unit” in “unit test” can involve bike-shedding.
So, just for the purposes of this book, so we can communicate, we’re going to squeeze the entire world of testing into exactly two buckets: Unit Tests and Integration Tests.