chapter eight

8 Our first feature

 

This chapter covers:

  • Feature file structure and syntax in detail
  • The main Gherkin keywords and how they should be used
  • Differentiating between context, action, and outcome
  • Using data tables and scenario outlines

Gherkin requires you to organize your scenarios into feature files. There’s no limit to how large (or small) your feature files are, but you should always remember that your goal is well structured, readable documentation.

Each feature file should focus on a single area of functionality in your product. As features get more complicated, you may find it useful to spread the documentation over several feature files. In Chapter 10, “Organizing the documentation”, we will talk in depth about how to structure documentation as it grows. For this chapter, we’re going to limit discussion to a single feature file.

The feature file that the team has just written describes how the system should enable a customer to place an order for customer-collection. The scenarios in this feature file are cohesive – they all illustrate related behavior of the software.

8.1 A sample feature file

The team has written scenarios for the example map that they built in the last chapter and replaced the old scenario completely. The scenarios have been collected into a feature file, which is shown in listing 8.1 and is also available at https://github.com/bddbooks/bddbooks-formulation-wimp/tree/main/ch3-beginning.

8.2 Gherkin basics

8.2.1 Keywords

8.2.2 Natural language

8.2.3 Strict reading of the text

8.3 The structure and syntax of a feature file

8.3.1 Rules

8.3.2 Scenario structure

8.3.3 Multiple contexts

8.3.4 Keeping context essential

8.3.5 Is it a Given or a When?

8.3.6 Multiple outcomes

8.3.7 Data tables

8.3.8 Scenario outlines

8.3.9 Keep tables readable

8.3.10 Readable blocks of text

8.4 Summary