In our previous post Behavior Driven Development we discussed BDD. Here, let's look at Cucumber. The flagship BDD framework for java, but not limited to Java.

Why Cucumber
As we saw in the previous post, until the Automation phase, BDD is all about discovering and formulating behavioral scenarios through collaboration. Its the automation phase, where things really happen.
It would be easy if we could write these behavioral scenarios in plain English (or another preferred spoken language) and runtime could understand and execute those for us. This is where Cucumber comes to the rescue.
Cucumber
Cucumber is a framework that let us write application-behavioral-expectations in meaningful spoken-language-text using Gherkin.
Cucumber implementations are available in many programming languages as shown below.

NOTE: It's recommended (not mandatory) to choose an implementation for the same platform or programming language as your production code.
However, if your behavioral tests codebase is under a different repo than your application code, and it's built and run on a different container or machine or environment. in that case you are free to choose any programing language of your liking.
Gherkin
Gherkin is a set of grammar rules that makes spoken-language-text structured enough for Cucumber to understand.
Gherkin has fixed keywords. When those Gherkin-keywords are used in a specific syntax, the cucumber engine translates them as instructions to execute. Gherkin-keywords are available in many spoken languages, in this post we’ll discuss only English Keywords.
Gherkin-keywords:
The Main (not all) keywords for the English language are:
- Feature
- Scenario / Example (Synonyms)
- Given
- When
- Then
- And
- But
- *
- Scenario Outline
- Background
- #
Cucumber tests are written with Gherkin grammar within a file ending with .feature
extension, also called feature-file.
This was a quick overview of Cucumber & Gherkin. In the next post Anatomy of Feature File we see how can we make use of these Gherkin keywords within a feature-file with proper grammar to write meaningful behavioral tests.
Comments