2016-10-04 22:33:06 +02:00
---
layout: pattern
title: Object Mother
folder: object-mother
permalink: /patterns/object-mother/
categories: Creational
2021-05-19 10:49:05 -06:00
language: en
2016-10-04 22:33:06 +02:00
tags:
2019-12-13 21:09:28 +02:00
- Instantiation
2016-10-04 22:33:06 +02:00
---
## Object Mother
Define a factory of immutable content with separated builder and factory interfaces.
2019-12-07 20:01:13 +02:00
## Class diagram
2016-10-04 22:33:06 +02:00

## Applicability
Use the Object Mother pattern when
* You want consistent objects over several tests
2019-12-13 21:09:28 +02:00
* You want to reduce code for creation of objects in tests
* Every test should run with fresh data
2016-10-04 22:33:06 +02:00
## Credits
* [Answer by David Brown ](http://stackoverflow.com/questions/923319/what-is-an-objectmother ) to the stackoverflow question: [What is an ObjectMother? ](http://stackoverflow.com/questions/923319/what-is-an-objectmother )
* [c2wiki - Object Mother ](http://c2.com/cgi/wiki?ObjectMother )
2017-03-25 22:07:10 +01:00
* [Nat Pryce - Test Data Builders: an alternative to the Object Mother pattern ](http://www.natpryce.com/articles/000714.html )