Introduction to Cucumber

Cucumber is a test framework that supports behavior-driven development (or BDD, in short). The core idea behind BDD is domain-specific language (known as DSL) where the tests are written in normal English, expressing how the application or system has to behave. DSL is an executable test that starts with a known state, performs some action, and verifies the expected state:

Given I launch the app
And I click on Register
Then I should see register with Facebook and Google
Dan North (creator of BDD) defined behavior-driven development in 2009 as --BDD is a second-generation, outside-in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology. It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters.

Cucumber feature files serve as a living documentation that can be implemented in many languages. It was first implemented in Ruby and later extended to Java. Some of the basic features of Cucumber are listed as follows:

  • The core of Cucumber is text files called features, which contain scenarios. These scenarios express the system or application behavior.
  • Scenario files consist of steps that are written following the syntax of Gherkin.

A sample feature file is as shown here:

Feature: Sign up

Scenario: Facebook Integration
A user should be able to register and log into the app by using the Facebook account.

Given I choose to sign up
And I select to sign up using Facebook
Then I should see a pop up with my Facebook account to continue
And I should be logged in once I allow

So, in the preceding example, Feature, Scenario, Given, But, Then, and And are keywords. Let's take a look at some of the most used keywords of Cucumber and what it means:

Feature: tests are grouped into features. We use this name because we want engineers to describe the features that a user will be able to use.

Scenario: A scenario expresses the behavior we want. Each feature contains several scenarios; each scenario is a example of how the system should behave in a particular situation. The expected behavior of the feature will be the total scenarios. For a feature to pass, all scenarios must pass.

Test Runner: There are different ways to run the feature file; however, we will use the JUnit runner initially and then move on to the gradle command for command-line execution.

So, I am hoping that we now have a brief idea of what Cucumber is. Further details can be read on their site (https://cucumber.io/). In the following section, we will create a feature file, write a scenario, implement the code behind, and execute it.

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

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