liveBook · Manning

Test resource

As explained in Effective Behavior-Driven Development

A test resource is an infrastructure component or other resource whose lifetime and availability are managed for test execution.

A test resource is a component that must be available during a scenario and cleaned up afterward. An application host and a simulated payment gateway are both test resources. Starting the gateway for every scenario works, but wastes time when only a few scenarios need it. section 16.1

For a scenario-lifetime resource, a before-scenario hook can start it and an after-scenario hook can stop it. Tagging only the scenarios that need the gateway keeps those hooks selective. If the application host needs the gateway at startup, specify hook order so the gateway starts first. section 16.1

Table 16.1 Resource usages and tagging strategies
Resource usage
Tagging strategy
Tag expression
Needed for all scenarios
No tags needed
n/a
Needed by a few scenarios
Tag scenarios that need the resource
@payment_gateway
Needed by most scenarios
Tag scenarios that do not need the resource
not @no_payment_gateway
A set of scenarios needs the resource, but each needs a different variation or configuration
Tag the scenarios with tags following a fixed format (e.g., @payment_gateway:<name>): @payment_gateway:stripe, @payment_gateway:paypal
Do not pass the tag expression to the hook attribute, but use the API of the scenario automation tool in the tag code to strip out the variation or configuration name from the scenario tags (see listing 16.5)

Compare tagging strategies for resources needed by a few scenarios, most scenarios, or scenarios requiring different configurations. section 16.1

How Effective Behavior-Driven Development covers it

How deep it goes
Explains scenario-lifetime startup and cleanup through hooks, then compares tagging, hook ordering, and dependency-injection strategies.
Examples
Uses an application host and a simulated payment gateway, with tagged scenarios and hook listings.
What it assumes
Assumes familiarity with scenarios and hooks while defining test resources through concrete infrastructure examples.
What you can do after
Operate/configure scenario-lifetime resources using selective hooks and explicit initialization order when dependencies require it.
How it connects
Connects test resources to scenario hooks, tags, shareable scenario context, and dependency injection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Behavior-Driven Development. The section links point to the parts of the book it draws on.