Behavior-Driven Development (BDD) Examples
- BDD Is a Cooperative Game
- Addressing Some Concerns
- Playing the BDD Game
- Summary
- References
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
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 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 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