7 From examples to executable specifications

 

This chapter covers

  • Turning concrete examples into executable scenarios
  • Writing basic scenarios
  • Using data tables to drive scenarios
  • Writing more advanced scenarios using more Gherkin keywords
  • Organizing scenarios

In the last chapter, you saw how conversations with the stakeholders around business rules and concrete examples are a very effective way to build up a common understanding of a problem space. In this chapter, you’ll learn how to express these examples clearly and precisely in a way that will allow you to transform them into executable specifications and living documentation (see figure 7.1).

Figure 7.1 In this chapter we’ll take examples we used to discuss and illustrate features in previous chapters and turn them into executable specifications.

The aim of this chapter is to help developers, business analysts, testers, and other interested team members get a solid shared understanding of how to read and write executable specifications in a way that makes it easy to automate them. BDD has a number of well-defined practices to achieve this shared understanding:

7.1 Turning concrete examples into executable scenarios

7.2 Writing executable scenarios

7.2.1 A feature file has a title and a description

7.2.2 Describing the scenarios

7.2.3 The Given ... When ... Then structure

7.2.4 Ands and buts

7.2.5 Comments

7.3 Using tables in scenarios

7.3.1 Using tables in individual steps

7.3.2 Using tables of examples

7.3.3 Pending scenarios

7.4 Organizing your scenarios using feature files and tags

7.4.1 The scenarios go in a feature file