
644
Chapter 24 Test Organization Patterns
programming language doesn’t support inheritance (e.g., Visual Basic 5 or 6),
perhaps we are already using inheritance for some other confl icting purpose,
or perhaps the Test Utility Method needs access to specifi c types that are not
visible from the Testcase Superclass.
The decision between a Test Helper and a Testcase Superclass comes down
to type visibility. The client classes need to see the Test Utility Method, and the
Test Utility Method needs to see all the types and classes it depends on. When
it doesn’t depend on many types/classes or when everything it depends on is
visible from a single place, we can put the Test Utility Method into a common
Testcase Superclass we defi ne for our project or company. If the Test Utility
Method depends on types/classes that cannot be seen from a single place that all
clients can access, it may be necessary to put it on a Test Helper in the appropri-
ate test package or subsystem. In larger systems with many groups of domain
objects, it is common practice to have one Test Helper for each group (package)
of related domain objects.
Variation: Test Fixture Registry
A Registry [PEAA] is a well-known object that can be accessed from anywhere
in a program. We can use the Registry to store and retrieve objects from dif-
ferent parts of our program or tests. (Registry objects are often confused with
Singletons [GOF], which are also well known but have only a single instance.
With a Registry object, there may be one or more instances—we don’t really
care.) A Test Fixture Registry gives the tests the ability to access the same fi xture
as other tests in the same test run. Depending on how we implement our Test
Helper, we may choose to provide a different instance of the Test Fixture Regis-
try for each Test Runner (page 377) in an effort to prevent a Test Run War (see
Erratic Test on page 228). A common example of a Test Fixture Registry is the
Database Sandbox (page 650).
A Test Fixture Registry is typically used with a Setup Decorator (page 447) or
with Lazy Setup (page 435); it isn’t needed with Suite Fixture Setup (page 441)
because only tests on the same Testcase Class need to share the fi xture. In such
a case, using a fi xture holding class variable works well for this purpose.
Variation: Object Mother
The Object Mother pattern is simply an aggregate of several other patterns, each
of which makes a small but signifi cant contribution to making the test fi xture easier
to manage. The Object Mother consists of one or more Test Helpers that provide
Creation Methods (page 415) and Attachment Methods (see Creation Method),
which our tests then use to create ready-to-use test fi xture objects. Object Mothers
Test Helper