chapter eight

8 Formulating a 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, so in this chapter, we’re going to limit discussion to a single feature file. As features get more complicated, you may find it useful to spread the documentation over several feature files, but we’ll discuss that in a later chapter.

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.

Have a look through the feature file and the example map in figure 7.1. Can you see how they relate to each other? Do the scenarios conform to the BRIEF principles?

8.2 Gherkin basics

8.2.1 Keywords

8.2.2 Non-English language support

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.4 Gherkin tables

8.4.1 Data tables

8.4.2 Scenario outlines and examples tables

8.4.3 Data variations

8.4.4 Similar wording

8.4.5 Keep tables readable

8.5 Readable blocks of text

8.6 Summary