Suppose an address-change scenario needs an order waiting for pickup. Replaying order placement and the kitchen workflow would establish that state, but neither workflow is what the scenario is trying to verify. A context shortcut prepares the required state directly, leaving the scenario focused on whether the address change is allowed. section 16.2
Use the shortcut behind a business-readable Given step, such as “the customer has an order that is waiting for pickup.” One implementation calls a test-only REST endpoint to prepare the order, then saves its order number for later steps. Use shortcuts only for Given steps: the actions and outcomes being tested must still run and be checked. section 16.2
Choose the shortcut with its trade-off in view:
- It can make setup faster and less dependent on other workflows, allowing address-change behavior to be checked in isolation. section 16.2
- It can also create an unrealistic order and produce a false result. Compare the prepared state with one reached through normal actions, and use programmer tests where needed to check the preparation code. section 16.2
Table 16.4 Comparison of application state ensuring strategies
|
Sequence of
test actions
|
Context shortcut
|
|
Slower, more brittle
|
Faster, more robust
|
|
More dependent: The functionality
that brings the application to the required state must already be implemented
and working correctly to be able to verify the tested functionality
|
Loosely coupled: The functionality
skipped by the shortcut can be independently scheduled and verified
|
|
Any bug in any of the test actions
makes it impossible to verify the functionality illustrated by the scenario
|
The quality of the functionality
illustrated by the scenario can be assessed in isolation
|
|
The verification is consistent with
real usage
|
The verification might provide false
results if the shortcut is not consistent with the result of the action
sequence
|
|
The existing test drivers can be
reused
|
The shortcut is an additional
implementation task, and a dedicated backdoor API might be required that is
only accessible from the tests
|
Compare replaying test actions with preparing state directly, including the speed, independence, and realism trade-offs. section 16.2
