chapter twenty one

21 Stagecraft patterns for interacting with external resources

 

This chapter covers

  • Avoiding unnecessary initializations of external resources
  • Enabling the parallel execution of scenarios that depend on costly external resources
  • Simplifying automation code by encapsulating all operations that interact with the file system
  • Some common approaches to testing behaviors that depend on asynchronous operations

The behavior of our systems frequently depends on external components that are costly to provision, slow to initialize, and complicated to interact with. Nonetheless, we still want to receive fast feedback from running our tests, so we need techniques that can help minimize any degradation to test execution that these external components introduce.

In theatre, the technical aspects of a production are collectively known as Stagecraft. The patterns described in this chapter provide low-level, behind-the-scene solutions to several technical challenges related to effective test automation:

21.1 Test Environment Initialization pattern: getting ready for test execution

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

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

21.4 Patterns for asynchronous resources

21.4.1 Active Waiting pattern: keep polling the resource

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

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

21.5 Summary