You are previewing Growing Object-Oriented Software, Guided by Tests.

Growing Object-Oriented Software, Guided by Tests

Cover of Growing Object-Oriented Software, Guided by Tests by Steve Freeman... Published by Addison-Wesley Professional
O'Reilly logo

Chapter 22. Constructing Complex Test Data

Many attempts to communicate are nullified by saying too much.

—Robert Greenleaf

Introduction

If we are strict about our use of constructors and immutable value objects, constructing objects in tests can be a chore. In production code, we construct such objects in relatively few places and all the required values are available to hand from, for example, user input, a database query, or a received message. In tests, however, we have to provide all the constructor arguments every time we want to create an object:

image

The code to create all these objects makes the tests hard to read, filling them with information ...

The best content for your career. Discover unlimited learning on demand for around $1/day.