Careeroza
What Is BDD and Gherkin
BDD in One Paragraph
Behaviour-Driven Development (BDD) means the business analyst, developer and tester agree on examples of behaviour before coding, written in plain English. Cucumber runs those examples as automated tests. The language of the examples is called Gherkin.
| Keyword | Meaning |
|---|---|
Feature | the feature being described (one per file) |
Scenario | one example / test case |
Given | starting state (precondition) |
When | the action the user takes |
Then | the expected result |
And / But | more steps of the same kind |
Background | steps shared by every scenario in the file |
A Feature File
Example
src/test/resources/features/login.feature
Feature: Login
As a ShopEase customer
I want to log in
So that I can see my orders
Background:
Given the user is on the login page
@smoke
Scenario: Valid login
When the user logs in with "[email protected]" and "Secret@123"
Then the welcome message "Welcome, Asha" is shown
Scenario: Wrong password
When the user logs in with "[email protected]" and "wrong"
Then the error "Invalid email or password" is shownDependencies
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.20.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>7.20.1</version>
<scope>test</scope>
</dependency>Note: BDD is a collaboration practice. If only testers read the feature files, Cucumber adds a layer without the benefit; plain TestNG + POM may be simpler.