
Fixture (a Fresh Fixture) or whether we will build it once as a Shared Fixture
and reuse it across many tests.
When to Use It
When I was reviewing an early draft of this book with Series Editor Martin
Fowler, he asked me, “Do people actually do this?” This question exemplifi es
the philosophical divide of fi xture design. Coming from an agile background,
Martin lets each test pull a fi xture into existence. If several tests happen to need
the same fi xture, then it makes sense to factor it out into the setUp method and
split the class into one Testcase Class per Fixture (page 631). It doesn’t even occur
to Martin to design a Standard Fixture that all tests can use. So who uses them?
Standard Fixtures are something of a tradition in the testing (quality assess-
ment) community. It is very commonplace to defi ne a large Standard Fixture that
is then used as a test bed for testing activities. This approach makes a lot of sense
in the context of manual execution of many customer tests because it eliminates
the need for each tester to spend a lot of time setting up the test environment for
each customer test and it allows several testers to work in the same test environ-
ment at the same time. Some test automaters also use Standard Fixtures when
defi ning their automated customer tests. This strategy is especially prevalent
when test automaters use a Shared Fixture, for obvious reasons.
In the xUnit community, use of a Standard Fixture simply to avoid designing a
Minimal Fixture (page 302) for each test is considered undesirable and has been
given the name General Fixture (see Obscure Test on page 186). A more accepted
example is the use of Implicit Setup (page 424) in conjunction with Testcase
Class per Fixture because only a few Test Methods (page 348) share the design
of the fi xture and they do so because they need the same design. As we make a
Standard Fixture more reusable across many tests with disparate needs, it tends
to grow larger and more complex. This trend can lead to a Fragile Fixture (see
Fragile Test on page 239) as the needs of new tests introduce changes that break
existing clients of the Standard Fixture. Depending on how we go about building
the Standard Fixture, we may also fi nd ourselves entertaining a Mystery Guest
(see Obscure Test) if the cause–effect relationships between the fi xture and out-
come are not easy to discern either because the fi xture setup is hidden from the
test or because it is not clear which characteristics of the referenced part of the
Standard Fixture serve as pre-conditions for the test.
A Standard Fixture will also take longer to build than a Minimal Fixture
because there is more fi xture to construct. When we are building a Fresh Fixture
for each Testcase Object (page 382), this effort can lead to Slow Tests (page 253),
especially if the fi xture setup involves a database. (See the sidebar “Unit Test Rulz”
Standard
Fixture
306
Chapter 18 Test Strategy Patterns