Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an ObjectMother?

Tags:

What is an ObjectMother and what are common usage scenarios for this pattern?

like image 418
Oded Avatar asked May 28 '09 21:05

Oded


2 Answers

ObjectMother starts with the factory pattern, by delivering prefabricated test-ready objects via a simple method call. It moves beyond the realm of the factory by facilitating the customization of created objects, providing methods to update the objects during the tests, and if necessary, deleting the object from the database at the completion of the test.

Some reasons to use ObjectMother:
* Reduce code duplication in tests, increasing test maintainability
* Make test objects super-easily accessible, encouraging developers to write more tests.
* Every test runs with fresh data.
* Tests always clean up after themselves.

(http://c2.com/cgi/wiki?ObjectMother)

like image 128
David Brown Avatar answered Sep 24 '22 23:09

David Brown


See "Test Data Builders: an alternative to the Object Mother pattern" for an argument of why to use a Test Data Builder instead of an Object Mother. It explains what both are.

like image 41
cwash Avatar answered Sep 25 '22 23:09

cwash