19 Technical note patterns for quick error recovery
The chapter explains that fast error recovery in BDD depends on making failures easier to diagnose as soon as they happen. Because automated scenarios often exercise multiple layers of the system, a failure may appear far from its true cause, especially in CI/CD pipelines where debugging is limited. The central idea is to enrich scenario execution results with enough context, logging, and health checks that developers can quickly understand what happened and why.
One major theme is improving the quality of failure information. The text recommends writing descriptive assertion messages that include the relevant business context, and using supplementary attachments when important diagnostic data does not fit neatly into the message itself. It also describes building a structured test log that reflects the layers of the automation solution, and, when useful, embedding application logs directly into that same log so there is a single place to inspect during investigation. The chapter emphasizes keeping these logs readable by default while still allowing more detail when needed, such as through tags or higher verbosity levels.
Beyond reporting failures, the chapter also focuses on catching problems earlier and preventing hidden issues from slipping through. It introduces corroboration checks that fail a scenario when the application log shows warnings or errors, even if the visible behavior still passes, and fail-fast checks that verify setup steps truly established the required context before later steps continue. Together, these patterns support more trustworthy automation by surfacing root causes sooner, reducing wasted debugging time, and making BDD scenarios better at protecting both behavior and system health.
report generated by scenario automation tool
Application log entries are embedded in the test logs
Summary
- When applying continuous integration (CI), fixing a build failure in the CI pipeline automatically becomes the team’s highest priority. This makes it essential that assertions are designed to make the diagnosis and fixing of an error as simple as possible.
- The Descriptive Assertion pattern emphasizes the importance of including as much relevant context information as possible in an assertion error message.
- The Red-Green-Refactor loop requires the developer to see a step fail before they implement the code required to make it pass. It is important to check that the information provided when the step fails contains sufficient information to assist with diagnosis and fixing.
- The Supplementary Attachment pattern provides a way to attach relevant context to an assertion error message when it can’t be included in the message itself. This maybe because there is too much text to comfortably fit in the message, or because the attachment is not textual, such as a screenshot.
- The test automation solution can be complicated, so the Test Log pattern describes how to meaningfully log the runtime flow of the test automation solution. This is important, because an assertion error marks the end of test, but the failure is often caused by operations that preceded it.
- The test log is most helpful when presented as a hierarchical artefact, so that flow of control is clear.
- Too much detail in a log can make it hard to see what is important, as well as filling storage up with inessential information. The level of detail included in the test log can be controlled by many different mechanisms, including configuration or feature file tags.
- Hierarchical presentation of a log file can simplify error diagnosis.
- It’s ultimately the application’s behavior that we’re interested in, so there is often useful information relating to a failure in the application log. It can be useful to apply the Embedded Application Log pattern, which embeds some of application log statements directly into the test log.
- Since it’s during the When step that a specific behavior is invoked, it can be useful to automatically increase the detail of application log statements embedded during their execution.
- For tricky errors, it can be useful to identify specific situations in which logging levels should be automatically increased – such as during an automatic retry of a failed scenario.
- The application log often contains warnings or errors that don’t directly cause a scenario to fail but might indicate some potential issues with the health of the application. The Corroboration Check pattern raises an error in these situations, to ensure the development team performs a manual corroboration that all is well.
- There are situations when an application warning or error are unimportant. In these cases, the health check should be disabled for the scenario or step.
- If a context setup call fails without raising an exception, the scenario may still fail if a later relies on that context. The Fail-fast pattern has the context setup step explicitly check that the context has been set up correctly and abort the scenario immediately.
- Fail-fast checks should be implemented generically whenever possible.
Effective Behavior-Driven Development ebook for free