12 Getting ready for scenario automation
This chapter explains how teams can approach scenario automation without rushing into a brittle or costly solution. It opens by showing that automation projects often fail to deliver the promised speed and reliability, so the safer approach is to treat automation as a set of experiments, especially when the team lacks experience or the product is not yet easy to test. A proof-of-concept lets the team learn, try out options, and build confidence before automating everything, reducing the risk of accumulating quality debt that slows delivery later.
The chapter then introduces design patterns as a way to capture recurring automation solutions and reuse them consistently. It emphasizes that patterns are general solutions for specific contexts, should be documented clearly with their intent, applicability, and tradeoffs, and can be organized into pattern languages that help teams navigate related choices. The chapter also surveys scenario automation tool capabilities, including step definitions, expressions and parameters, custom parameter types, hooks, and glue code organization, while highlighting differences between tools such as Reqnroll and Cucumber-JVM.
Finally, the chapter presents the SUITABLE principles for effective scenario automation: use shortcuts to set up context efficiently, provide understandable diagnostics, keep scenarios isolated, treat test code as first-class code, prefer atomic assertions, use business terminology, design for loose coupling, and maintain fast feedback. It concludes by framing automation strategy as a set of architectural choices: which interface layer to test through, whether to use real infrastructure or stubs, and how to balance speed, robustness, and confidence. The central message is that good scenario automation is deliberate, maintainable, and guided by experimentation rather than by rigid rules or a browser-only mindset.
Map of idiomatic scenario pattern languages
Map of flexible automation pattern languages
Developer workflow for automating a scenario
Conceptual approach for matching step text to step definition
A simple folder hierarchy for glue code
Various possible automation interface layers
Summary
- Take a low risk, proof-of-concept approach to adopting BDD automation.
- Software design patterns are a concise way to document successful solutions for future reference.
- A scenario automation tool is a tool that turns scenarios into automated tests, such as Cucumber and Reqnroll.
- Glue code is what we call the automation code that is invoked by the scenario automation tool, because it connects the specification to the system being developed.
- Step definitions are the blocks of glue code invoked by the scenario automation tool in response to text in the scenarios.
- The scenario automation tool determines which step definition to call by matching the text in the specification against all expressions used when registering step definitions.
- Scenario automation tools will signal an error if a step doesn’t match exactly one registration expression.
- Most scenario automation tools support step definition registration expressions written using either Cucumber Expressions or regular expressions.
- In addition to the step text, that is matched against the registration expressions, steps can also contain extra information (contained in docstrings and data tables) that can be passed to the step definition.
- The development team can define Custom parameter types to ensure that step definition registration expressions can accurately model domain concepts.
- Hooks are blocks of glue code that are called by the scenario automation tool, in response to predefined events in the execution process, such as before every scenario or after all scenarios have been run.
- There are eight key principles of BDD automation, captured by the SUITABLE mnemonic.
- Short cuts automation engineers should use appropriate mechanisms to accelerate scenario setup.
- Understandable diagnostics reduce the cognitive load when the system does not behave as specified.
- Isolated scenarios can be run repeatably no matter whether they are run on their own or as part of a larger set of scenarios.
- Test-code quality is just as important as production code quality.
- Atomic assertions ensure that all the available diagnostic information is provided whenever a scenario fails.
- Business terminology should be used throughout the system—from business-facing documentation to implementation code.
- Loose coupling is desirable to make code components testable on their own—without needing to always test through the UI or utilize resource hungry dependencies.
- Evolving software using the iterative and incremental BDD approach requires fast, frequent feedback.
- It is critical to choose a test automation strategy that maximizes confidence in the product while minimizing the time it takes to get feedback.
- The test automation pyramid is a useful metaphor that can help you design your test automation strategy.
Effective Behavior-Driven Development ebook for free