Cucumber Basics
Plan
Learn the basics of Cucumber
Prerequisites
- Java
- Maven - https://maven.apache.org/install.html
- GitHub Repository
https://github.com/smarigowda/CucumberBasics
Practice
Setup
Create a Maven project
mvn archetype:generate -DgroupId=com.tryonyourown.cucumber.basics -DartifactId=CucumberBasics -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Add dependencies into
pom.xml
cucumber-java
cucumber-junit
Notes
Cucumber provides a common interface for Business, QA and Developers
Also use it for requirement analysis
Encourages team to use conversations and concrete examples to build up a shared understanding
BDD style
Given, When, Then, Feature, Featue File, Scenario, Scenario Outline
Use
And
for multiple pre conditions or actions of positive typeUse
But
for multiple pre conditions or actions of negative typeStep Definition file will have the actual code
One to one mapping for step definition and its implementation
Feature - A high level business requirement
Feature file contains multiple scenarios
Feature file will have
.feature
as extensionTidyGherkin
Chrome plugin. Generates step definitions implementation template from feature file inputTest Runner
@CucumberOptions
features
- points to the feature file or the folderglue
- points to step definition package name
@RunWith
Cucumber.class
Same step definition can provide different implementaton. This can be achieved by using regular expressions in step definition.
Arguments should match with regex
Test Runner
- We provive the info of
Feature
files andStep Definition
files to the Test Runner - JUnit and TestNG are examples of test runners
- Test Runner executes Feature files
- We provive the info of
Provides higher level of abstraction
Uses
Gherkin
syntaxOpen Source
Features
- Data drivern
- Parameterization
- Execution Controls
- Hooks
Gherkin
- Business readable
- Domain Specific Language
- A medium that both computers and humans can understand
- Helps team colloboration
- Serves as documentation
BDD is more than just using Cucumber
- Talk about concrete examples of a User Story/ New Functionality to explore, discover and agree on the details of what's expected
- Over time, the documented examples become an asset that enables your team to continue confidently and rapidly making changes to the system
- The code reflects the documentation, and the documentation reflects the team’s shared understanding of the problem domain. This shared understanding is constantly evolving.