
131
• We can ask the fi le system to notify the test whenever a fi le is created or
modifi ed so we can verify its contents.
• We can use a database trigger to notify the test when a record is written
or deleted.
• We can confi gure the e-mail sending component to deliver all outgoing
e-mail to the test.
Sometimes, as we have seen with indirect inputs, it is not practical to use the
real component as an observation point. When all else fails, we may need to
replace the real component with a test-specifi c alternative. For example, we
might need to do this for the following reasons:
• The calls to (or the internal state of) the DOC cannot be queried.
• The real component can be queried but doing so is cost-prohibitive.
• The real component can be queried but doing so has unacceptable side
effects.
• The real component is not yet available for use.
The replacement of the real component can be done in a number of different
ways, as will be discussed in Installing the Test Double.
Two basic styles of indirect output verifi cation are available. Procedural Behav-
ior Verifi cation (see Behavior Verifi cation) captures the calls to a DOC (or their re-
sults) during SUT execution and then compares them with the expected calls after
the SUT has fi nished executing. This verifi cation involves replacing a substitutable
dependency with a Test Spy (page 538). During execution of the SUT, the Test Spy
receives the calls and records them. After the Test Method (page 348) has fi nished
exercising the SUT, it retrieves the actual calls from the Test Spy and uses Assertion
Methods (page 362) to compare them with the expected calls (Figure 11.6).
Expected Behavior (see Behavior Verifi cation) involves building a “behavior
specifi cation” during the fi xture setup phase of the test and then comparing the
actual behavior with this Expected Behavior. It is typically done by loading a
Mock Object (page 544) with a set of expected procedure call descriptions and
installing this object into the SUT (Figure 11.7). During execution of the SUT,
the Mock Object receives the calls and compares them to the previously defi ned
expected calls (the “behavior specifi cation”). As the test proceeds, if the Mock
Object receives an unexpected call, it fails the test immediately. The test failure
traceback will show the exact location in the SUT where the problem occurred
because the Assertion Methods are called from the Mock Object, which is in
turn called by the SUT. We can also see exactly where in the Test Method the
SUT was being exercised.
What Are Indirect Inputs and Outputs?