What We Just Learned

Let’s review what we’ve talked about in this chapter:

  • We saw how the Gherkin keywords Feature, Scenario, Given, When, and Then can be used to describe the behavior your stakeholders want as examples.

  • There is a fundamental pattern to each Gherkin scenario, with a context (Given), an event (When), and an outcome (Then).

  • Each scenario must be capable of being run on its own and should not depend on data set up by other scenarios. This means every scenario has to include enough Given steps to set up all the data it needs.

  • You can add descriptions and comments to your .feature files to turn them into useful documentation of your system.

  • Using the #language: header, you can write your features in different spoken languages.

At this point you have all the knowledge you need to get started writing your own Gherkin features. Even though there are some keywords we haven’t covered yet, there’s a huge amount of value in what you already know. Just pretend you have a machine that can turn your Cucumber scenarios into perfect working code, and play the game of working with your team to create the best descriptions you can of what you want the software to do.

In the next chapter, we’ll start to explore step definitions, the layer beneath the Gherkin features where you interact with your application, and bring your scenarios to life.

Try This

Here are some exercises for you to try.

Practice Given/When/Then

Let’s build a robot! Here’s a scenario:

 Scenario​: Tickle a happy robot
  Given I am in a good mood
  When you tickle me
  Then I will giggle

What happens if you change the context in which this scenario happens? Write another scenario where the first step puts the robot into a bad mood. Leave the action the same. What will be the outcome when you tickle a grumpy robot?

Now try changing the action:

 Scenario​: Attack a happy robot
  Given I am in a good mood
  When you kick me in the shins
  Then I will ...

What will the outcome be now?

Your First Scenario

Write the first formal Gherkin scenario for your project. Pick a feature you’re working on now, and try to describe the way the system should behave when you’re done. Notice when you have questions about the precise language you should use, or the precise behavior, and write them down. Try to get some time with the right people on your team to answer those questions. Show them the scenario: does it make sense to them? How would they have worded it?

Footnotes

[5]

Agile Estimating and Planning [Coh05]

[6]

The tar pit metaphor comes from the seminal book by Fred Brooks, The Mythical Man Month: Essays on Software Engineering [Bro95].

[7]

Extreme Programming Explained: Embrace Change [Bec00]

[8]

A note for the pedantic reader: the Gherkin language does have a grammar enforced by a parser, but the language is not Turing Complete.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.198.81