1. Tests
2. Features
3. Principles
-
Given
-
When
-
Then
-
And
4. Examples
4.1. Some review activity (No code)

4.2. This course materials! (No code)

4.3. Android example
Feature: Book Search
Scenario: Search books by author
Given there's a book called "Tips for job interviews" written by "John Smith"
And there's a book called "Bananas and their many colors" written by "James Doe"
And there's a book called "Mama look I'm a rock star" written by "John Smith"
When an employee searches by author "John Smith"
Then 2 books should be found
And Book 1 has the title "Tips for job interviews"
And Book 2 has the title "Mama look I'm a rock star"
4.4. Angular example
A "Getting Started" app
Some feature description

Running Cucumber (fail)

Write Steps definitions
This is code linking the assertions with the running code.
import { When, Then } from 'cucumber';
When('we request the products list', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
Then('we should receive', function (dataTable) {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
Running Cucumber (pass)

5. Supported languages
Ruby (origin), Java, JavaScript,
6. Build
Make sure to integrate BDD in your build.
For maven/gradle, see https://cucumber.io/docs/tools/java/#build-tools
7. Find a plugin for your IDE

Example for VS Code: https://github.com/alexkrechik/VSCucumberAutoComplete
8. Gherkin tips
8.1. Avoid duplication


Sometimes you want to relax your language, to make it flow better.

@Given("I go to the {string} page")
public void i_want_to_open_page(String webpage) {
webpageFactory.openPage(webpage);
}
8.2. Grouping step definitions
One file for each major domain object.
EmployeeStepDefinitions.java
EducationStepDefinitions.java
ExperienceStepDefinitions.java
AuthenticationStepDefinitions.java
8.3. Scenario outline (template)

8.4. Language support
Over 70 languages!
Don’t forget the # language: fr !
|

9. How-to
10. Concepts
10.1. Feature
What follows is a basic description or name of the feature being tested or documented.
10.2. Rule
-
represent a business rule that should be implemented
-
used to group together several scenarios
New concept (since Gherkin v6) |
10.3. Background
Steps that will be ran before every scenario in the feature.
10.4. Scenario
Name or basic description of a particular scenario testing the feature.
10.5. Scenario Outline
The scenario will run N times for every argument listed in examples explicitly passed by column name wrapped in angled brackets.
A Scenario Outline must contain one or more Examples |
10.6. Examples
The list of static arguments that will be passed into a scenario outline.
10.7. The AAA pattern
// arrange
var component = ComponentFixture<UserUploadComponent>;
var user = new User(component);
// act
user.Save();
// assert
mock.Received.SomeMethod();
10.8. Given
A given step, or precondition that is assumed before continuing.
In the Arrange, Act, Assert paradigm, given represents "Arrange". |
10.9. When
A when step, or the behavior that is to be asserted against.
In the Arrange, Act, Assert paradigm, given represents "Act". |
10.10. Then
A then step, or in other words, the step in which a behavior’s result is validated.
In the Arrange, Act, Assert paradigm, given represents "Assert". |
10.11. And
Used in conjunction with any of the keywords above.
If you have two given statements, instead of explicitly calling Given twice, you can say, " Given A And B". |
11. Links between US and feature


12. Links between Features and their implementation

13. CI/CD and BDD

15. Not just for code!







