TestDataBuilder
Last edit September 29, 2011
An alternative to
ObjectMother
that uses the
BuilderPattern
to create objects in
ProgrammerTests
.
ObjectMother
does not cope well with variability in the test data being created, except by allowing the user of the objects to modify them. That doesn't work if the
ObjectMother
creates
ValueObject
s (because
ValueObjectsShouldBeImmutable
).
The
TestDataBuilder
pattern allows tests to specify only those parts of the objects that need to vary and use sensible defaults for those that are not relevant to the test.
For a longer description, see:
http://www.natpryce.com/articles/000714.html
. This document links to techniques for using and building upon
TestDataBuilder
s.
This article describes how
MockObject
s and
TestDataBuilder
s work together:
http://www.valuablecode.com/2009/03/are-you-using-mocks-when-you-should-be-using-test-data-builders/
Make It Easy (
http://code.google.com/p/make-it-easy/
) is a tiny framework to help the writing of Test Data Builders in Java and C#.
PojoBuilder
(
http://github.com/mkarneim/pojobuilder
) is a Java annotation processor that can be used to generate the source code of Test Data Builders automatically.