
the post-test state of the SUT via a back door to compare it with expected
outcome. For customer tests, the back door is most commonly a test database,
but it could also be some other component on which the SUT depends, including
a Registry [PEAA] object or even the fi le system. For unit tests, the back
door is some other class or object or an alternative interface of the SUT (or a
Test-Specifi c Subclass; page 579) that exposes the state in a way “normal” clients
wouldn’t use. We can also replace a depended-on component (DOC) with a
suitably confi gured Test Double (page 522) instead of using the real thing if
that makes the job easier.
When to Use It
We might choose to use Back Door Manipulation for several reasons which we’ll
examine in more detail shortly. A prerequisite for using this technique is that some
sort of back door to the state of the system must exist. The main drawback of
Back Door Manipulation is that our tests—or the Test Utility Methods (page 599)
they call—become much more closely coupled to the design decisions we make
about how to represent the state of the SUT. If we need to change those decisions,
we may encounter Fragile Tests (page 239). We need to decide whether this price
is acceptable on a case-by-case basis. We can greatly reduce the impact of the close
coupling by encapsulating all Back Door Manipulation in Test Utility Methods.
Using Back Door Manipulation can also lead to Obscure Tests (page 186) by
hiding the relationship of the test outcome to the test fi xture. We can avoid this
problem by including the test data being passed to the Back Door Manipulation
mechanism within the Testcase Class (page 373), or at least mitigate it by using
Finder Methods (see Test Utility Method) to refer to the objects in the fi xture
via intent-revealing names.
A common application of Back Door Manipulation involves testing basic
CRUD (Create, Read, Update, Delete) operations on the SUT’s state. In such a
case, we want to verify that the information persisted and can be recovered in the
same form. It is diffi cult to write round-trip tests for “Read” without also testing
“Create”; likewise, it is diffi cult to test “Update” or “Delete” without testing both
“Create” and “Read.” We can certainly test these operations by using round-trip
tests, but this kind of testing won’t detect certain types of systemic problems, such
as putting information into the wrong database column. One solution is to con-
duct layer-crossing tests that use
Back Door Manipulation to set up or verify the
contents of the database directly. For a “Read” test, the test sets up the contents
of the database using Back Door Setup and then asks the SUT to read the data.
For a “Write” test, the test asks the system to write certain objects and then uses
Back Door Verifi cation on the contents of the database.
Back Door
Manipulation
Chapter 18 Test Strategy Patterns
328