SlideShare a Scribd company logo
Behavior Driven Development
Pravin D’silva
MCA
Goa University
AGENDA
Introduction
 TDD
 BDD
 Cucumber
 Gherkin
 Step Definitions
 Demo (Ruby)
 How to extend

INTRODUCTION
People have a lot of ideas in mind.
 The key to convert ideas to software:
COMMUNICATION
 Various stakeholders involved in completing the
task

WRONG PERCEPTION
TEST DRIVEN DEVELOPMENT
Automated Test Cases
 Produce minimum code to pass test
 Refactor code to acceptable standards

TDD
Advantages:
 Programmers tend to be
more productive
 Can drive the design of a
program
 Offers the ability to take
small steps
 Can lead to more
modularized, flexible, and
extensible code

Shortcomings
 Reliance on unit tests
might not perform
sufficient full functional
testing
 Tests may share the
same blind spots with the
code
 Tests become part of the
maintenance overhead of
a project
 Rewrite the tests when
requirements change
WHAT IS BDD?
“BDD builds upon TDD by formalizing the good
habits of the best TDD practitioners.”
- Matt Wynne
So what are those good habits?
 Working outside-in, starting from a business or
organizational goal
 Using examples to clarify requirements
 Developing and using a ubiquitous language
USE OF EXAMPLES
Take care to write the acceptance tests as
examples that anyone on the team can read
 Get feedback from the business stakeholders
 Ensure the acceptance tests can easily be read and
written by anyone on the team


Easier to validate
 Readable by computer




TRUE VALUE OF ACCEPTANCE TESTS
communication
 collaboration tool

In BDD
Acceptance Tests
are
EXECUTABLE
SPECIFICATIONS
CUCUMBER TESTING STACK
Gherkin:
1. Specifications from plain-language text files
called features.
2. Each scenario is a list of steps for Cucumber
to work through
Step Definitions:
Map the business-readable language of each
step into Ruby code to carry out
whatever action is being described by the step.
Automation library:
One or two lines of Ruby that delegate
to a library of support code, specific to the
domain of your application.
CUCUMBER TESTING STACK
GHERKIN
Cucumber tests are expressed using a syntax
called Gherkin.
 Gherkin files: plain text and have a .feature
extension
 Use of Concrete Examples
 Lets take a scenario


Customers should be prevented from entering invalid
credit card details.
PROBLEMS
Customers should be prevented from entering invalid credit
card details.






Ambiguity and Misunderstanding
Lacks precision
Worthy but vague

Lets take another scenario
If a customer enters a credit card number that isn’t
exactly 16 digits long, when they try to submit the
form, it should be redisplayed with an error message
advising them of the correct number of digits.
FEATURE
Describe the features that a user will be able to enjoy when
using a program
Feature: Feedback when entering invalid credit card details.


In user testing we've seen a lot of people who made mistakes
entering their credit card. We need to be as helpful as possible
here to avoid losing users at this crucial stage of the transaction.

Background:
Given I have chosen some items to buy
And I am about to enter my credit card details
Scenario: Credit card number too short
When I enter a card number that's only 15 digits long
And all the other details are correct
And I submit the form
Then the form should be redisplayed And I should see a
message advising me of the correct number of digits
SCENARIO


Each scenario is a single concrete example of how the
system should behave in a particular situation



Scenarios all follow the same pattern:
1. Get the system into a particular state.
2. Poke it (or tickle it, or ...).
3. Examine the new state.









Start with a context, go on to describe an action, and
then finally check
that the outcome was what we expected. Each scenario
tells a little story describing something that the system
should be able to do.
SUPPORT FOR VARIOUS LANGUAGES
Gherkin support in Hindi
"native": "
feature": "
background": "
scenario": "
scenario_outline": "
examples": "
given": "*|
when": "*|
then": "*|
and": "*|
but": "*|

Norwegian:
Egenskap: Summering
For å unngå at firmaet går konkurs
Må regnskapsførerere bruke en
regnemaskin for å legge sammen tall
Scenario: to tall
Gitt at jeg har tastet inn 5
Og at jeg har tastet inn 7
Når jeg summerer
Så skal resultatet være 12
STEP LANGUAGES


Translates from plain language into Ruby



On the inside it tells your system what to do using
Ruby automation code.



Ruby has an incredibly rich set of libraries for
automating a whole variety of systems, from
JavaScript-heavy web applications to REST web
services.
FEATURE TO STEP DEFINITION
Feature:

Given I have $100 in my account
Regular Expression:
 /I have $100 in my Account/
KEYWORDS
Feature
 Background
 Scenario
 Given
 When
 Then
 And
 But
*
 Scenario Outline
 Examples

DEMO EXAMPLE
AFTER CREATING THE STEP DEFINITIONS FILE

The scenario has graduated from undefined to
pending.
Given /^the input "([^"]*)"$/ do |input|
@input = input
end
When /^the calculator is run$/ do
@output = `ruby calc.rb #{@input}`
raise('Command failed!') unless $?.success?
end
Calc.rb is not found


After calc.rb is created (still blank)
print eval(ARGV[0]) in calc.rb
Then /^the output should be "([^"]*)"$/ do |expected_output|
@output=expected_output
end
ADDING ANOTHER SCENARIO
Scenario Outline: Add two numbers
Given the input "<input>"
When the calculator is run
Then the output should be "<output>"
Examples:
| input | output |
| 2+2 | 4 |
| 98+1 | 99 |
ALL TESTS PASSED
ADDITIONAL USES OF CUCUMBER
Databases
 Testing REST web services
 Capybara to Test Ajax Web Applications
 Aruba

USE CUCUMBER WITH JVM
Install Maven
 Install m2e plugins for Eclipse
 Add Cucumber dependencies in pom.xml
 Run Maven builds and test using Cucumber

REFERENCES
http://www.slideshare.net/tabaradetestare/t
dt-bdd-gabi-kis?from_search=14
https://github.com/cucumber/cucumber-jvm
http://rspec.info/
http://c0deattack.wordpress.com/2012/03/2
8/cucumber-jvm-with-cucumber-javacucumber-junit-example/
http://www.slideshare.net/ousam/cucumber
-presenation

More Related Content

PPTX
Introduction to Bdd and cucumber
PPTX
BDD WITH CUCUMBER AND JAVA
PDF
BDD & Cucumber
PPTX
Automation test framework with cucumber – BDD
PPT
Cucumber presentation
PDF
Cucumber ppt
PPTX
Test Automation Framework with BDD and Cucumber
Introduction to Bdd and cucumber
BDD WITH CUCUMBER AND JAVA
BDD & Cucumber
Automation test framework with cucumber – BDD
Cucumber presentation
Cucumber ppt
Test Automation Framework with BDD and Cucumber

What's hot (20)

ODP
BDD with Cucumber
ODP
Test Automation Framework using Cucumber BDD overview (part 1)
PPSX
Cucumber & gherkin language
PDF
Selenium with Cucumber
PPTX
Cucumber presenation
PPTX
Automated Test Framework with Cucumber
PPTX
What Is Cucumber?
PPTX
Bdd – with cucumber and gherkin
PPTX
Cucumber With Selenium
PPTX
BDD testing with cucumber
PDF
Introduction to BDD with Cucumber for Java
PPTX
Setting up Page Object Model in Automation Framework
PDF
Introducing BDD and TDD with Cucumber
PPTX
Cucumber Tool
PDF
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
PPTX
Cucumber_Training_ForQA
PDF
PPTX
API Automation Testing Using RestAssured+Cucumber
PPT
Test Automation Strategies For Agile
ODP
Introduction to BDD
BDD with Cucumber
Test Automation Framework using Cucumber BDD overview (part 1)
Cucumber & gherkin language
Selenium with Cucumber
Cucumber presenation
Automated Test Framework with Cucumber
What Is Cucumber?
Bdd – with cucumber and gherkin
Cucumber With Selenium
BDD testing with cucumber
Introduction to BDD with Cucumber for Java
Setting up Page Object Model in Automation Framework
Introducing BDD and TDD with Cucumber
Cucumber Tool
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
Cucumber_Training_ForQA
API Automation Testing Using RestAssured+Cucumber
Test Automation Strategies For Agile
Introduction to BDD
Ad

Similar to Cucumber BDD (20)

PPTX
Behavior Driven Development - TdT@Cluj #15
PPTX
Xamariners - BDD + Mobile
PDF
Why BDD is our BFF
PPTX
BDD Selenium for Agile Teams - User Stories
PDF
Advanced Test Automation: WDIO with BDD Cucumber
PPTX
1501 meetup
PPTX
PDF
Behavioral Driven Development
PPTX
Cucumber jvm best practices v3
PDF
Behavior Driven Development with Cucumber
PDF
Behaviour driven infrastructure
PPTX
Introduction to Behaviour Driven Development (BDD) and Cucumber with Java
PDF
Cucumbers Have Layers - RubyConf 2015
PDF
Behavior Driven Development
PDF
Cucumbers Have Layers: A Love Story (AATC 2017)
PDF
Specification-by-Example: A Cucumber Implementation
PDF
What is Gherkin or Cucumber testing.pdf
PPTX
Bdd in action
PPTX
Rubyconf2016 - Solving communication problems in distributed teams with BDD
PDF
An Introduction to Behaviour Driven Development with Cucumber Java
Behavior Driven Development - TdT@Cluj #15
Xamariners - BDD + Mobile
Why BDD is our BFF
BDD Selenium for Agile Teams - User Stories
Advanced Test Automation: WDIO with BDD Cucumber
1501 meetup
Behavioral Driven Development
Cucumber jvm best practices v3
Behavior Driven Development with Cucumber
Behaviour driven infrastructure
Introduction to Behaviour Driven Development (BDD) and Cucumber with Java
Cucumbers Have Layers - RubyConf 2015
Behavior Driven Development
Cucumbers Have Layers: A Love Story (AATC 2017)
Specification-by-Example: A Cucumber Implementation
What is Gherkin or Cucumber testing.pdf
Bdd in action
Rubyconf2016 - Solving communication problems in distributed teams with BDD
An Introduction to Behaviour Driven Development with Cucumber Java
Ad

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Cloud computing and distributed systems.
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced IT Governance
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Cloud computing and distributed systems.
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Weekly Chronicles - August'25 Week I
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced IT Governance
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
Understanding_Digital_Forensics_Presentation.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Cucumber BDD

  • 1. Behavior Driven Development Pravin D’silva MCA Goa University
  • 2. AGENDA Introduction  TDD  BDD  Cucumber  Gherkin  Step Definitions  Demo (Ruby)  How to extend 
  • 3. INTRODUCTION People have a lot of ideas in mind.  The key to convert ideas to software: COMMUNICATION  Various stakeholders involved in completing the task 
  • 5. TEST DRIVEN DEVELOPMENT Automated Test Cases  Produce minimum code to pass test  Refactor code to acceptable standards 
  • 6. TDD Advantages:  Programmers tend to be more productive  Can drive the design of a program  Offers the ability to take small steps  Can lead to more modularized, flexible, and extensible code Shortcomings  Reliance on unit tests might not perform sufficient full functional testing  Tests may share the same blind spots with the code  Tests become part of the maintenance overhead of a project  Rewrite the tests when requirements change
  • 7. WHAT IS BDD? “BDD builds upon TDD by formalizing the good habits of the best TDD practitioners.” - Matt Wynne So what are those good habits?  Working outside-in, starting from a business or organizational goal  Using examples to clarify requirements  Developing and using a ubiquitous language
  • 8. USE OF EXAMPLES Take care to write the acceptance tests as examples that anyone on the team can read  Get feedback from the business stakeholders  Ensure the acceptance tests can easily be read and written by anyone on the team  Easier to validate  Readable by computer   TRUE VALUE OF ACCEPTANCE TESTS communication  collaboration tool 
  • 10. CUCUMBER TESTING STACK Gherkin: 1. Specifications from plain-language text files called features. 2. Each scenario is a list of steps for Cucumber to work through Step Definitions: Map the business-readable language of each step into Ruby code to carry out whatever action is being described by the step. Automation library: One or two lines of Ruby that delegate to a library of support code, specific to the domain of your application.
  • 12. GHERKIN Cucumber tests are expressed using a syntax called Gherkin.  Gherkin files: plain text and have a .feature extension  Use of Concrete Examples  Lets take a scenario  Customers should be prevented from entering invalid credit card details.
  • 13. PROBLEMS Customers should be prevented from entering invalid credit card details.     Ambiguity and Misunderstanding Lacks precision Worthy but vague Lets take another scenario If a customer enters a credit card number that isn’t exactly 16 digits long, when they try to submit the form, it should be redisplayed with an error message advising them of the correct number of digits.
  • 14. FEATURE Describe the features that a user will be able to enjoy when using a program Feature: Feedback when entering invalid credit card details.  In user testing we've seen a lot of people who made mistakes entering their credit card. We need to be as helpful as possible here to avoid losing users at this crucial stage of the transaction. Background: Given I have chosen some items to buy And I am about to enter my credit card details Scenario: Credit card number too short When I enter a card number that's only 15 digits long And all the other details are correct And I submit the form Then the form should be redisplayed And I should see a message advising me of the correct number of digits
  • 15. SCENARIO  Each scenario is a single concrete example of how the system should behave in a particular situation  Scenarios all follow the same pattern: 1. Get the system into a particular state. 2. Poke it (or tickle it, or ...). 3. Examine the new state.      Start with a context, go on to describe an action, and then finally check that the outcome was what we expected. Each scenario tells a little story describing something that the system should be able to do.
  • 16. SUPPORT FOR VARIOUS LANGUAGES Gherkin support in Hindi "native": " feature": " background": " scenario": " scenario_outline": " examples": " given": "*| when": "*| then": "*| and": "*| but": "*| Norwegian: Egenskap: Summering For å unngå at firmaet går konkurs Må regnskapsførerere bruke en regnemaskin for å legge sammen tall Scenario: to tall Gitt at jeg har tastet inn 5 Og at jeg har tastet inn 7 Når jeg summerer Så skal resultatet være 12
  • 17. STEP LANGUAGES  Translates from plain language into Ruby  On the inside it tells your system what to do using Ruby automation code.  Ruby has an incredibly rich set of libraries for automating a whole variety of systems, from JavaScript-heavy web applications to REST web services.
  • 18. FEATURE TO STEP DEFINITION Feature: Given I have $100 in my account Regular Expression:  /I have $100 in my Account/
  • 19. KEYWORDS Feature  Background  Scenario  Given  When  Then  And  But *  Scenario Outline  Examples 
  • 21. AFTER CREATING THE STEP DEFINITIONS FILE The scenario has graduated from undefined to pending.
  • 22. Given /^the input "([^"]*)"$/ do |input| @input = input end
  • 23. When /^the calculator is run$/ do @output = `ruby calc.rb #{@input}` raise('Command failed!') unless $?.success? end Calc.rb is not found
  • 24.  After calc.rb is created (still blank)
  • 25. print eval(ARGV[0]) in calc.rb Then /^the output should be "([^"]*)"$/ do |expected_output| @output=expected_output end
  • 26. ADDING ANOTHER SCENARIO Scenario Outline: Add two numbers Given the input "<input>" When the calculator is run Then the output should be "<output>" Examples: | input | output | | 2+2 | 4 | | 98+1 | 99 |
  • 28. ADDITIONAL USES OF CUCUMBER Databases  Testing REST web services  Capybara to Test Ajax Web Applications  Aruba 
  • 29. USE CUCUMBER WITH JVM Install Maven  Install m2e plugins for Eclipse  Add Cucumber dependencies in pom.xml  Run Maven builds and test using Cucumber 