Overview

11 Coping with legacy

The chapter explains how BDD can be introduced into legacy codebases, where much of the software already exists without strong automated tests. In that setting, teams often need to recover knowledge about current behavior before they can improve or extend the system safely. The text emphasizes that this kind of reverse engineering can be useful, but it is not the same as true BDD, because BDD is about discovering and shaping behavior before implementation, not just documenting what is already there.

A key message is that teams should avoid treating Gherkin and Cucumber as synonyms for BDD. Using scenarios only to automate already-built functionality may provide some testing value, but it does not deliver the architectural and collaborative benefits of behavior-driven work. Because legacy systems were often built without failing scenarios guiding development, they are frequently more tightly coupled and harder to test at lower levels, which makes end-to-end automation tempting but expensive. Instead of documenting everything, the chapter recommends an incremental, risk-based approach that focuses on areas about to change, important business behaviors, or parts of the system that are most likely to evolve.

The chapter also cautions against blindly converting existing manual test scripts into automated scenarios. Manual scripts and illustrative scenarios serve different goals, so direct conversion often creates brittle documentation with high maintenance cost and little added insight. Some scripts may be useful as inspiration for identifying important behaviors or as prompts for conversations with testers and other experts, but each one should be evaluated on its own merits. Overall, the best use of legacy artifacts is to support understanding and selective documentation, while preserving the BDD principle that scenarios should clarify behavior and guide implementation rather than merely preserve old tests.

Summary

  • Using Gherkin to capture test scripts is not an indication that the software has been developed in a behavior-driven way
  • Focus retrospective Gherkin documentation efforts on areas of functionality that are about to (or likely to) change
  • Don’t convert manual test scripts directly into Gherkin, because this will not result in good illustrative scenarios
  • Analyze every legacy test script before formulating it into Gherkin to ensure that only valuable documentation is created
  • Make use of any personnel that have knowledge of the legacy product, especially the testers

FAQ

What does chapter 11 mean by “legacy code,” and why is it so common?Legacy code is described as code without tests. By that definition, most existing software becomes legacy code at some point. The chapter argues that because teams often adopt BDD partway through delivery, they need practical ways to work with code that already exists rather than starting from scratch.
Is using Gherkin scenarios for test automation the same as doing BDD?No. The chapter makes it clear that simply writing Gherkin scenarios to automate already-implemented functionality is not BDD. BDD expects discovery and formulation to happen before implementation, so the scenarios drive development rather than just verify code after the fact.
Why is recovering behavior from legacy code useful if it is not “real” BDD?Although it is not BDD in the strict sense, reverse engineering behavior through example mapping and illustrative scenarios is still valuable. It helps developers avoid breaking existing behavior, and it gives stakeholders a clearer understanding of what the system currently does.
Should a team try to document the entire legacy codebase with Gherkin?Usually not. The chapter recommends a risk-based, incremental strategy instead of trying to cover everything. Most teams will get better results by focusing on selected areas of the system rather than attempting full documentation all at once.
What is a good starting point for documenting legacy behavior?A strong starting point is an area the team is about to modify. Documenting behavior in the code they will soon change increases confidence and reduces the risk of introducing regressions. Once the current behavior is understood, the team can then implement changes in a behavior-driven way.
How does the 80/20 rule apply to legacy documentation?The chapter suggests that teams can often get most of the value by documenting a small number of core behaviors. Instead of aiming for exhaustive coverage, domain experts should identify the most important behaviors across the application and focus on those.
Why should teams avoid documenting too many journey scenarios in a legacy system?Journey scenarios can create a large maintenance burden if overused. The chapter warns that teams should resist documenting end-to-end journeys when focused behaviors would be more useful, because journey-style coverage is harder to maintain and often less informative.
Which legacy areas are best to document first based on probability of change?Areas that change frequently are the best candidates. The chapter recommends using source control history to identify parts of the system that are often modified, since those areas offer the greatest return on the effort spent documenting them.
What should a team do with existing manual test scripts?They should not automatically convert them into Gherkin scenarios. Manual scripts and illustrative scenarios serve different purposes, so the team should analyze scripts individually, keep the useful knowledge, and replace them with targeted scenarios only when that adds real value.
Why is it better to ask testers or other project people than to rely only on old test scripts?Because test scripts often do not explain why they were created or what they were meant to prove. The chapter advises talking to people who worked on the project—especially testers—since they may have deep domain knowledge and can clarify the intent behind the old scripts more efficiently than reading them alone.

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


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 ebook for free
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 ebook for free