liveBook · Manning

Object mother

An object mother is a test-data creation pattern that provides reusable methods or objects for constructing valid, preconfigured test fixtures.

How 2 Manning books explain it

Effective Behavior-Driven Development

A test-data construction pattern that provides methods for creating default objects or object hierarchies customized for particular tests.

How it is used
Creates customized default objects and hierarchies for scenario test data while keeping incidental details out of scenario descriptions.
How deep it goes
Works through an optional-parameter method and a separate order builder, while declining a one-size-fits-all interface design.
Examples
Uses pizza items with selected names or sizes and orders with one default item or multiple customized items.
What you can do after
Build it from scratch as a small customization method or an order builder that returns scenario-ready test data.

Read how Effective Behavior-Driven Development explains object mother →

Test Driven: Practical TDD and Acceptance TDD for Java Developers

A test-support pattern in which an object or set of objects provides complete, valid domain objects and supports their customization and lifecycle management.

How it is used
Centralizes test-object creation methods to reduce duplicated fixture setup across test classes.
How deep it goes
Defines a sophisticated factory through object completeness, lifecycle access, customization, updates, and cleanup.
Examples
Uses Person fixtures for Alice, Billy, and Clark, including a relationship between Alice and Billy.
What you can do after
Build it from scratch by gathering fixture creation methods in a helper that supplies and manages valid domain objects.

Read how Test Driven: Practical TDD and Acceptance TDD for Java Developers explains object mother →

Also covered in

Related concepts

Questions about object mother

What is object mother?

An object mother is a test-data creation pattern that provides reusable methods or objects for constructing valid, preconfigured test fixtures.

Which Manning books explain object mother?

Effective Behavior-Driven Development and Test Driven: Practical TDD and Acceptance TDD for Java Developers.

What should I know before learning object mother?

Manning books that teach object mother usually introduce application code first.

What is object mother part of?

Object mother is part of A Pattern Language. A pattern language is a structured collection of interrelated patterns that describes recurring problems and their relationships within a domain.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.