Summary

Provides a single place to put the logic to handle the construction and customization of objects for use in testing.

Description

When testing against the domain you probably want to consider doing state based testing using real domain objects, in Fowler speak this means classical TDD testing. This affects your tests because in the test fixture setup phase we end up creating lots of test objects, to quote Fowler:

With classic TDD, you have to create not just the SUT but also all the collaborators that the SUT needs in response to the test. While the example only had a couple of objects, real tests often involve a large amount of secondary objects. Usually these objects are created and torn down with each run of the tests.

An obvious way to handle this is to create test Factory classes. These classes would have a variety of methods on them, including normal creation methods and methods that give you a domain object in a particular state. As Meszaros states an OBJECT MOTHER is thus a combination of several smaller patterns.

Testing using classicist TDD against the public interface of our domain objects has several advantages and disadvantages and you may want to consider also doing behavior tests using mocking, this topic is discussed at this link.

Links

Martin Fowler - Classical and Mockist Testing
xUnit Patterns - Creation Methods

Last edited Aug 27, 2007 at 9:42 AM by colin_jack, version 2

Comments

No comments yet.