Home > Articles

Behavior-Driven Development (BDD) Examples

A look at how to explore the behavior of a new user story by collaborating around examples with a cross-functional team.

Save 35% off the list price* of the related book or multi-format eBook (EPUB + MOBI + PDF) with discount code ARTICLE.
* See informit.com/terms

This chapter is from the book

As we said in Chapter 1, “Focusing on Value,” the first and most important part of BDD is exploring desired system behavior with examples in conversations.

We set the stage for conversations around examples by finding valuable slices of functionality on which to focus in the form of MMFs and user stories. In this chapter, we look at how to explore the behavior of a new user story by collaborating around examples with a cross-functional team.

BDD Is a Cooperative Game

In Alistair Cockburn’s book Agile Software Development: The Cooperative Game, he characterizes software development as a “cooperative game of invention and communication.” In competitive games, like tennis, there is a clear notion of winning and losing. Even in team games, like basketball, one team wins and the other loses. But in cooperative games, people work to win together.

Games can also be finite or infinite. A finite game, like chess, is one that intends to have an end. On the other hand, an infinite game, like the game an organization or nation typically plays, is about prolonging one’s existence.

Games can be finite and goal-seeking, like chess, or they can be finite and nongoal-directed, like jazz, where the process is the focus—there’s not a defined goal that would cause you to “win” the song.

If we combine these ideas to get a goal-seeking, finite, cooperative game, we see activities like rock climbing or adventure racing, where a group of people work together to reach a goal together as fast as possible. Software development, especially Agile software development, is a similar game. Software development is a finite, goal-seeking, cooperative, group game.

BDD is an Agile subdiscipline of the game of software development. The emphasis in BDD is particularly placed on helping the team cooperate, innovate, and communicate during the game, all with the intention of achieving the goal of creating valuable working software more quickly and effectively.

BDD Is a Whole Team Thing

Teams who find their way into BDD via a tool like Cucumber often get the misunderstanding that BDD is a test automation approach that mostly concerns testers and developers.

BDD is a whole-team practice. It’s a way of structuring the collaboration required to build the right software. As such, it involves all the roles on the team.

Product owners bring an understanding of the customer and realistic examples of a user doing something with the software. Testers bring their unique perspectives about what could go wrong; they’re great at proposing examples outside the happy path. Developers understand the implications of a particular example on implementation and often have a good understanding of the existing system and the problems it solves. Technical writers contribute skills with language and often empathy for how users talk about what they do in the system.

Early in adopting BDD, collaboration tends to occur as a whole team. This allows the team to build a common language for their domain. Later, smaller groups can leverage that language to collaborate, and the work they produce will be comprehensible to the rest of the team.

Because we see so much value in the whole team participating in the collaboration in BDD, we rarely teach public BDD classes. If only some team members understand how to work in this way, the team is unlikely to experience the benefits. We’ve seen cases where just the testers or just the developers get excited about a tool like Cucumber and just end up doing test automation, the least valuable part of BDD, in isolation.

Allow Time and Space to Learn

Did you notice how Jonah warned the team it wasn’t going to be easy? Adopting a new way of working takes time and practice. It takes a willingness to muddle through until the new skills become natural. It’s easy to forget what we went through to adopt our current skills—they weren’t always as natural as they seem now.

Sometimes it feels like you can’t afford the time to learn something new. Maybe someone committed you to deliver a big project (with defined scope) by a particular date, and it doesn’t feel like you have any room to slow down. In that case, feature mining from Chapter 1 is your secret weapon.

These big release or project commitments that feel so fixed and overwhelming are usually fairly high-level. We know we have to deliver, say, the new sales reporting by June 15. But within the bullet point of “new sales reporting,” there’s high-value work and there’s low-value work. Feature mining gives us a way to focus on the high-value work and avoid the low-value work, thereby making the deadline less scary and buying some extra capacity for improvement.

We also don’t recommend adopting a new practice like BDD for all your work all at once. Instead, we recommend you use what we call the “slow lane” approach. Say you’ve planned eight user stories in your sprint. Most stories will use your existing definition of done, which doesn’t include BDD. Choose one or two to be in the “slow lane” across your board (see Figure 2-1). For those, you’ll use the new practice. And you won’t feel as pressured when you do it because you’ve already agreed those will take longer.

FIGURE 2.1

Figure 2.1 A task board with two stories designated as slow lane stories

The early adopters on your team who are excited about the new practice will tend to sign up for those stories, working out the issues and establishing patterns for those who prefer to “wait and see.”

After a while, expand the slow lane to three or four stories. Eventually, you’ll notice that the stories with the new practice really aren’t that much slower (and probably turn out faster in the end because they have fewer defects and less rework). At that point, make the new practice part of your definition of done for every story.

Some teams move from the slow lane to fully adopting BDD in just two or three sprints. Others take their time and do it over four to six months. There’s no rush. It’s better to adopt a practice slowly, deliberately, and well than to rush into it badly and give up under pressure.

Flesh Out the Happy Path First

It’s often easy to come up with a bunch of examples right away, but we recommend talking all the way through at least one core example before getting deep in variations. By talking through a “happy path” example, a common case where things work as they should, the team gets a shared understanding of what the user story is about. What does it look like when the user is able to do what they want to do?

This complete slice also helps validate the story. Sometimes a story that sounds quite reasonable in the abstract reveals mistaken assumptions when you get into a core example. “Wait a minute,” someone says, “no user would actually do it that way.”

Once everyone understands the happy path, it often becomes more clear which variations are reasonable and likely. Instead of brainstorming every possible variation and edge case, realistic examples float to the top and focus the team on getting to value quickly. (The less likely variations and edge cases can be useful for exploratory testing, by the way. More on this and how it relates to BDD in Chapter 3, “Formalizing Examples into Scenarios.”)

Use Real Examples

Notice the team’s happy path example wasn’t just about “a book” or “Title ASDF”; it was an example of a real book that a real library patron might borrow. Good examples put you in the user’s shoes, building empathy for what the user is trying to do and helping you think more accurately about how they’ll do it.

It wasn’t a coincidence that using Words of Radiance for the example led the team to realize they already had test data to use. A real example connected the team to the system full of real inventory they already had at the library. This is not unusual. One real thing connects to other real things. We frequently see teams make discoveries about functionality, design, and architecture when they get into concrete, realistic examples.

Example Mapping Gives the Discussion Structure

Our favorite way to add some light structure to this kind of discussion is with Matt Wynne’s Example Mapping technique.1 In Example Mapping, the group builds a tree: the story has rules that are illustrated by examples. Assumptions and questions are captured on the side so the core discussion about examples doesn’t get blocked by side conversations. The result looks something like Figure 2-2.

FIGURE 2-2

Figure 2-2 Example Mapping

Discussions about examples necessarily lead to rabbit trails—side topics that could distract from the core topic—because reality is complex and interlinked. In the meeting we just looked at, the team allowed side topics to naturally emerge but retained focus on the core topic with a facilitation tool called a parking lot. The parking lot is simply a place to capture things that are worth talking about but not right now.

In Example Mapping, pink stickies typically function as the parking lot—the questions and assumptions that otherwise might take over the discussion. But yellow, green, or blue stickies could capture stories, examples, or rules to be included in a future discussion.

Jane captured a note about audiobooks, for example. Audiobooks were explicitly out of scope for the current feature, but they were worth thinking about. Mark will probably take that note, convert it into a product backlog item, and prioritize it appropriately.

Using a parking lot balances the needs to be open to diverse contributions and to capture important discussion topics with the need to respect meeting participants’ time by keeping the meeting focused. We use variations on this technique in almost everything we facilitate.

Optimizing for Discovery

You might be surprised that the team proceeds with work on this user story before nailing down all the rules and examples. Rather than working in a series of phases— planning, analysis, development, testing—the team is working iteratively in very small cycles. They’re planning and analyzing a little, doing some test design, developing some production code, doing a little more testing, going back to planning, and so on.

The traditional approach to software development assumes we not only have a clear understanding of the goal of a software system but also the means to achieve that goal, and that we know both well ahead of when the software needs to be delivered to the customer. This implies that there is no need to further explore the customer’s space, since we already know what the customer requires. The waterfall development process is the logical outcome of this kind of thinking: the means of accomplishing the goal are called requirements, and all that is needed is for us to implement the requirements as software features. In industrial work, we want to manage for consistent, repeatable, predictable results; we want our goals to be as clear and unambiguous as possible. Waterfall development takes the same approach as industrial work.

In knowledge work we need to manage for creativity. We are generating something new rather than just incrementally improving on the past. This means there is no way to precisely define the goal in advance, because there are too many unknowns. Software development is knowledge work, and Agile development is fundamentally a considered response to this situation of not knowing the exact goal and how to reach it. Agile promotes embracing and adapting to change to be the chief concern of the development process. Thus, teams doing Agile development optimize for discovery, as the Manifesto for Agile Software Development says, valuing “responding to change over following a plan.” Furthermore, “Agile processes harness change for the customer’s competitive advantage.”

This ability to respond quickly to new learning is thus at the heart of agility in software development. “The path to the goal is not clear, and the goal may in fact change.”2 An Agile team will often start out with the intention of solving a customer’s problem in a certain way but discover their assumptions about that customer need are wrong. They might discover that the real need is actually different from what they thought, which then leads to a very different solution.

There is no such thing as “requirements”; there are only unvalidated assumptions. The goal of delivering MMFs is to validate our assumptions as soon as possible, in case they turn out to be false and we need to change direction. Agile development assumes that the specific destination is unknown, so we need to iterate our way there. Software development is inherently a discovery process.

In knowledge work we need to imagine a world that doesn’t exist yet and embrace exploration, experimentation, and trial and error. We are bringing fuzzy goals into reality. A fuzzy goal is one that “motivates the general direction of the work, without blinding the team to opportunities along the journey.”3 This is the journey we hope to demonstrate in this book, as the library development team adopts BDD and employs it to enable them to get better at delivering predictably in the face of fuzzy goals. “Fuzzy goals must give a team a sense of direction and purpose while leaving team members free to follow their intuition.”4

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020