Overview

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
report generated by scenario automation tool
Application log entries are embedded in the test logs
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.

FAQ

What is the main goal of the technical note patterns in this chapter?The main goal is to make failing BDD scenarios easier and faster to diagnose by providing better context, richer logs, and earlier detection of setup or health problems.
Why should assertion error messages include extra context information?Extra context helps you understand not just what failed, but why it failed, reducing the time needed to trace the root cause of the problem.
When should the Supplementary Attachment pattern be used?Use it when the useful debugging information is too large or not suitable to include directly in the assertion message, such as logs or screenshots that can be attached to the test result.
How does the Test Log pattern help with troubleshooting failing scenarios?It records the execution flow of the scenario in a structured way, showing what actions were performed, in what order, and with what inputs and outputs.
What is the advantage of embedding application logs into the test log?It creates a single, easier-to-follow source of diagnostic information, so you do not need to jump between separate test and application log files.
Why can embedded application logs become too verbose, and how can that be managed?They can include many low-level details, so teams often control verbosity with default log levels and tags that enable more detailed logging only when needed.
What does the Corroboration Check pattern verify?It checks for unexpected application health issues such as warnings or errors in the application log, even if the scenario’s main functional assertions still pass.
When is it appropriate to run health checks for application warnings or errors?Usually after the scenario has otherwise passed, so the health check does not hide functional failures or interfere with expected negative scenarios.
What problem does the Fail-fast Check pattern solve?It catches incorrect context setup immediately, instead of waiting for a later step to fail in a less obvious way.
What kinds of setup actions often need fail-fast checks?Typical examples include loading pages, making REST API calls, starting asynchronous work, or loading files where success is not guaranteed unless explicitly verified.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Effective Behavior-Driven Development Effective Behavior-Driven Development ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Effective Behavior-Driven Development Effective Behavior-Driven Development ebook for free