liveBook · Manning

Chapter 21: Stagecraft patterns for interacting with external resources

What you will learn in chapter 21 of Effective Behavior-Driven Development

This introduction explains why costly external resources can slow scenario tests and why sharing them complicates parallel execution.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains why costly external resources can slow scenario tests and why sharing them complicates parallel execution.

Key terms: external resources, fast feedback, test isolation, parallel execution, shared resources

21.1 Test Environment Initialization pattern: getting ready for test execution

This section explains how to initialize external resources efficiently for a test run, clean them up afterward, and account for the limits of test-run hooks.

Key terms: Test Environment Initialization pattern, before-test-run hook, before-scenario hook, database schema, scenario context, dependency injection (DI), static methods, database context factory, after-test-run hook, clean-up activities

21.2 Resource Pooling pattern: leasing pooled resources to scenarios running in parallel

This section explains how leasing costly external resources from a pool lets scenarios run in parallel without creating a new resource for every scenario.

Key terms: Resource Pooling pattern, resource pool, leased, test workers, parallel execution, DatabasePoolDriver, AcquireDatabase, ReleaseDatabase, lazy initialization, thread-safe

21.3 Test File System pattern: handling test files in a uniform way

This section explains how the Test File System pattern centralizes file-path decisions for test automation across execution environments.

Key terms: SUT, stub file system, test automation solution, current folder, test input files, TEMP environment variable, Test File System pattern, TestFileSystem, test input, test output

21.4 Patterns for asynchronous resources

This section explains why asynchronous external resources create timing problems for sequential scenarios and why language-level async constructs alone may not solve them.

Key terms: asynchronous resources, scenario execution, Then step, asynchronous programming constructs, asynchronous I/O, await, background process

21.4.1 Active Waiting pattern: keep polling the resource

This section explains how to poll for an asynchronous result in scenario automation, including the timing, race-condition, and timeout problems that polling introduces.

Key terms: Active Waiting, polling, asynchronous operation, fixed wait, sleep, delay between two subsequent polls, When step, Then step, system status, timeout period

21.4.2 Completed Event pattern: getting a notification when the resource produced some result

The section explains how completion notifications can replace polling for asynchronous results, why a timeout remains necessary, and how to provide notifications when a resource lacks them.

Key terms: Completed Event pattern, Active Waiting pattern, notification (event), overall timeout, notification, completion event functionality, façade, anti-corruption layer, active waiting

21.4.3 Synchronous Testing pattern: turning the asynchronous behavior to synchronous for testing

This section explains when synchronous processing can simplify tests that depend on asynchronous resources, and what those tests may fail to detect.

Key terms: Synchronous Testing pattern, asynchronous resource, synchronous processing, thread-safety issues, automation goal, main thread

21.5 Summary

Concepts explained in this chapter

← Chapter 20: Staging patterns for adapting test execution

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.