
when we wish to defi ne a Named Test Suite (page 592) that consists of a subset
of tests
7
chosen from other test suites and the framework does not support Test
Selection (page 403).
Many members of the xUnit family support Test Discovery at the Test Method
level but force us to use Test Enumeration at the Testcase Class level.
Implementation Notes
Building the Suite of Suites to be executed by the Test Runner involves two steps.
First, we must fi nd all Test Methods to be included in each Test Suite Object.
Second, we must fi nd all Test Suite Objects to be included in the test run, albeit
not necessarily in this order. Each of these steps may be done manually via
Test Method Enumeration and Test Suite Enumeration or automatically via Test
Method Discovery (see Test Discovery) and Testcase Class Discovery (see Test
Discovery). When done manually, we typically use a “Test Suite Factory” that
returns the Test Suite Object.
Variation: Test Suite Enumeration
Many members of the xUnit family require that we provide a Test Suite Factory
that builds the top-level Suite of Suites (often called “AllTests”) as means to
specify which Test Suite Objects we would like to include in a test run. We do
so by providing a class method on a factory class; this Factory Method [GOF]
is called suite in most members of the xUnit family. Inside the suite method we
use calls to methods such as addTest to add each nested Test Suite Object to the
suite we are building.
Although this approach is fairly fl exible, it can result in Lost Tests (see
Production Bugs on page 268). The alternative is to let the development tools
build the AllTests Suite (see Named Test Suite) automatically or to use a Test
Runner that fi nds all test suites in a fi le system directory automatically. For
example, NUnit provides a built-in mechanism that implements Testcase Class
Discovery at the assembly level. We can also use third-party tools such as Ant
to fi nd all Testcase Class fi les in a directory structure.
Even in statically typed languages such as Java, the Test Suite Factory (see
Test Enumeration on page 399) does not need to subclass a specifi c class or
implement a specifi c interface. Instead, the only dependencies are on the generic
Test Suite Object class it returns and the Testcase Classes or Test Suite Factories
it asks for the nested suites.
7
A Smoke Test [SCM] suite is a good example.
Test
Enumeration
400
Chapter 19 xUnit Basics Patterns