
161
deployed to the Web server (or not deployed to the Web server!). We usually
have at least a Subset Suite for all the unit tests and another Subset Suite for
just the customer tests (they often take a long time to execute). Some variants of
xUnit support Test Selection (page 403), which we can use instead of defi ning
Subset Suites.
Such runtime groupings of tests often refl ect the environment in which they
need to run. For example, we might have one Subset Suite that includes all tests
that can be run without the database and another Subset Suite that includes
all tests that depend on the database. Likewise, we might have separate Subset
Suites for tests that do, and do not, rely on the Web server. If our test package
includes these various kinds of test suites, we can defi ne AllTests as a Suite of
Suites (see Test Suite Object) composed of these Subset Suites. Then any test
that is added to one of the Subset Suites will also be run in AllTests without
incurring extra test maintenance effort.
Running a Single Test
Suppose a Test Method fails in our Testcase Class. We decide to put a break-
point on a particular method—but that method is called in every test. Our
fi rst reaction might be to just muddle through by clicking “Go” each time
the breakpoint is hit until we are being called from the test of interest. One
possibility is to disable (by commenting out) the other Test Methods so they
are not run. Another option is to rename the other Test Methods so that the
xUnit Test Discovery mechanism will not recognize them as tests. In variants
of xUnit that use method attributes or annotations, we can add the “Ignore”
attribute to a test method instead. Each of these approaches introduces the
potential problem of a Lost Test (see Production Bugs on page 268), although
the “Ignore” approach does remind us that some tests are being ignored. In
members of the xUnit family that provide a Test Tree Explorer (see Test Run-
ner), we can simply select a single test to be run from the hierarchy view of the
test suite, as shown in Figure 12.7.
When none of these options is available, we can use a Test Suite Factory to
run a single test. Wait a minute! Aren’t test suites all about running groups of
tests that live in different Testcase Classes? Well, yes, but that doesn’t mean
we can’t use them for other purposes. We can defi ne a Single Test Suite
4
(see
Named Test Suite) that runs a particular test. To do so, we call the constructor
of the Testcase Class with the specifi c Test Method’s name as an argument.
4
I usually call it MyTest.
Organizing Test Suites