How Cucumber works?
Assuming that we have read the previous posts on “Why Cucumber“, “ATDD, TDD &BDD” and “Continuous Test Automation” sections, we will see how Cucumber works and what are the touch points we need to understand while running Cucumber. This will be a high-level overview only. We will get into the details (Given, When, Then…) in a subsequent section.
When you run Cucumber, it reads in your specifications from plain-language text files called features, examines them for scenarios to test, and runs the scenarios against your system. Each scenario is a list of steps for Cucumber to work through.
Along with the features, you give Cucumber a set of step definitions, which
map the business-readable language of each step into <program> code to carry out
whatever action is being described by the step. In a mature test suite, the
step definition itself will probably just be one or two lines of code that delegate
to a library of support code, specific to the domain of your application, that
knows how to carry out common tasks on the system. Normally that will
involve using an automation library/framework. We have extensively talked about different frameworks and implemented them in our Tutorials under “Frameworks & Beyond“.
The step definitions are pretty much like blocks (functions) of code that map to the Cucumber steps. If there is an error or exception in any line of code inside the step definition block, Cucumber will mark that step RED in the result output and then moves on to execute the next step. In this way, we will know exactly which step failed and have to narrow down to the cause and debug from there on. The execution results will be printed to the Console by default, however there are many options for us to write the result log to a file , print it pretty, write in json, html and so on.
What is Gherkin?
Since Cucumber parses the feature files, that means it has to follow some syntax rules. The name given to this set of rules is Gherkin.
One view of how Cucumber works is as below. This is more from connecting the folder structure of a Cucumber project to the control flow of execution
Cucumber Testing Stack
Cucumber & Ruby Project (illustration)
From a RubyMine IDE, the project folder structure looks as below. We should be able to connect the Cucumber Testing Stack with the project folder view.
Cucumber & Java Project (illustration)
An illustration of a cucumber Java project looks as below.
Cucumber Overall Sequence Flow/Work Flow
On this page, we have discussed a high level overview of “How” Cucumber works. The diagrams above can be thought as more of architecture level diagrams. We will discuss more details in subsequent sections.