SlideShare a Scribd company logo
Seb  Rose  
seb@cucumber.io
@sebrose                                                                                                                                                                                                                                                                                                                                                                h0p://cucumber.io
An  Introduc9on  to    
Behaviour  Driven  Development  
with  
Cucumber  for  Java
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Agenda
-­‐ What  is  BDD?  
-­‐ What  is  Cucumber?  
-­‐ Demo  Cucumber  for  Java  
-­‐ Cucumber  variants  
-­‐ Pu@ng  it  all  together
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
What  is  BDD?
Behaviour Driven DevelopmentDesign
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
BDD   is   a   second-­‐generaBon,   outside-­‐in,   pull-­‐based,  
mulBple-­‐stakeholder,   mulBple-­‐scale,   high-­‐automaBon,  
agile  methodology.    
It   describes   a   cycle   of   interacBons   with   well-­‐defined  
outputs,   resulBng   in   the   delivery   of   working,   tested  
soJware  that  ma)ers.  
Dan  North
h)p://skillsma)er.com/podcast/java-­‐jee/how-­‐to-­‐sell-­‐bdd-­‐to-­‐the-­‐business
BDD  defined
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
The  power  of  “should”
-­‐Diverts  developers  from  their  distaste  for  tesBng  
-­‐Encourages  people  to  ask  “Should  it  really?”
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Deliberate  discovery
“…  during  an  incepBon,  when  we  are  most  
ignorant  about  most  aspects  of  the  project,  
the  best  use  we  can  possibly  make  of  the  Bme  
available  is  to  a)empt  to  idenBfy  and  reduce  
our  ignorance  …”  
Dan  North
h)p://dannorth.net/2010/08/30/introducing-­‐deliberate-­‐discovery/
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Ubiquitous  language
“The  pracBce  of  building  
up  a  common,  rigorous  
language  between  
developers  and  users”  
MarBn  Fowler
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
The  3  Amigos
The one where...
User  stories  &  
acceptance  
criteria
Examples
Open  
quesBons
Domain  
learning
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Example  mapping
Acceptance
Criterion
(Rule)
User Story
Example
Open
Question
Acceptance
Criterion
(Rule)
Acceptance
Criterion
(Rule)
Example
Example
Example
Example
Example
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Important  conversaBons
having  conversaBons    
is  more  important  than    
capturing  conversaBons    
is  more  important  than    
automa.ng  conversaBons  
Liz  Keogh
h)p://lizkeogh.com/2014/01/22/using-­‐bdd-­‐with-­‐legacy-­‐systems/
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Living  documentaBon
a.k.a  Executable  specificaBon
Living  documentaBon  is  a  reliable  and  
authoritaBve  source  of  informaBon  on  system  
funcBonality,  which  anyone  can  easily  access.    
It  is  as  reliable  as  the  code,  but  much  easier  to  
read  and  understand.  
Gojko  Adzic
h)p://specificaBonbyexample.com/key_ideas.html
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
What  BDD  is  not….
-­‐ Using  “Given/When/Then”  
-­‐ The  responsibility  of  testers  
-­‐ An  alternaBve  to  manual  tesBng
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
What  is  Cucumber?
Features
-Scenarios  
-­‐Steps
-Gherkin
Glue  code
-Step  definiBons
-Ruby  
-Java  
-C#  &  others
ApplicaBon
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Feature: Team Scoring
Teams start with zero score.
Correct answer gets points depending on 

how difficult it is.
Scenario: New teams should not have scored yet
Given I register a team
Then my score is 0
Scenario: Correctly answering a question scores points
Given I register a team
When I submit a correct answer
Then my score is 10
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Feature:  Feature  name  
Descrip8on  of  feature  goes  here  
Scenario:  Scenario  name  
Descrip8on  of  scenario  goes  here  
Given  a  certain  context  
When  something  happens  
Then  an  outcome  
And  something  else  
But  not  this  though  
Scenario:  Another  scenario  name  
...
Gherkin  fundamentals
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Given(/^I register a team$/) do
# Glue code goes here
end
Ruby
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
import cucumber.api.java.en.*;
public class MyStepDefinitions {
@Given("^I register a team$")
public void iRegisterATeam() throws Throwable {
// Glue code goes here
}
}
Java
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Cucumber  variants
• Ruby  
• C#  (Specflow)  
• Java  (&  other  JVM  languages)  
• Javascript  
• PHP  
• Python  
• C++
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Given/When/Then  namespaces
Global  namespace    
-­‐  Given/When/Then  interchangeable
Separate  namespaces    
-­‐  Given/When/Then  disBnct  
-­‐  And/But  bind  to  preceding  namespace  
-­‐  [StepDefiniBon]  for  compaBbility
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Binding  &  test  frameworks
Behind  the  scenes  
-­‐  may  need  to  specify  paths  
-­‐  select  required  plugin(s)
Some  magic  code  generaBon  
-­‐  NUnit  by  default  
-­‐  configuraBon  changes  for  others  
-­‐  several  output  opBons
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Sharing  data  between  steps
Varies  by  implementaBon  
-­‐  Ruby,  Javascript:  World  object  
-­‐  Java:  Dependency  InjecBon
Context  object(s)  
-­‐  Injected  
-­‐  Scenario  
-­‐  Feature
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Hooks
Before  &  AJer  
Ruby:  Around,  AJerStep
Before  &  AJer  
BeforeStep  &  AJerStep  
BeforeFeature  &  AJerFeature  
BeforeTestRun  &  AJerTestRun  
BeforeScenarioBlock  &  
AJerScenarioBlock
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Pu@ng  it  all  together
SoJware  development  is  hard.  
Understanding  what  your    
methods  and  tools    
are  good  for  
can  make  it  easier.
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Tools  are  not  essenBal
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
BDD   is   a   second-­‐generaBon,   outside-­‐in,   pull-­‐based,  
mulBple-­‐stakeholder,   mulBple-­‐scale,   high-­‐automaBon,  
agile  methodology.    
It   describes   a   cycle   of   interacBons   with   well-­‐defined  
outputs,   resulBng   in   the   delivery   of   working,   tested  
soJware  that  ma)ers.  
Dan  North
h)p://skillsma)er.com/podcast/java-­‐jee/how-­‐to-­‐sell-­‐bdd-­‐to-­‐the-­‐business
BDD  redefined
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
h)ps://cucumber.pro/blog/2014/03/03/the-­‐worlds-­‐most-­‐misunderstood-­‐collaboraBon-­‐tool.html
When  you  do  BDD/SpecificaBon  by  Example  and  Outside-­‐in,  
regression   tests   fall   out   at   the   other   end.   They   are   a   by-­‐
product  of  those  acBviBes.  TesBng  isn't  the  acBvity  itself.  
Cucumber  is  first  a  foremost  a  collaboraBon  tool  that  aims  to  
bring   a   common   understanding   to   soJware   teams   -­‐   across  
roles.  
Aslak  Hellesøy
It’s  about  collaboraBon
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
We  sBll  need  testers
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
h)p://claysnow.co.uk/architectural-­‐alignment-­‐and-­‐test-­‐induced-­‐design-­‐damage-­‐fallacy/
Test  =  check  +  explore
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
So  much  can  go  wrong!
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
h)p://1.bp.blogspot.com/_YzKCMr-­‐tcMM/TFLIGeqTJfI/AAAAAAAAARQ/AhNW62KX5EA/s1600/cartoon6.jpg
AutomaBon  is  development
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Understand  designs
Features
-Scenarios  
-­‐Steps
-Gherkin
Glue  code
-Step  definiBons
-Ruby  
-Java  
-C#  &  others ApplicaBon
Support  
code
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
This  page  intenBonally  blank.
<role>  will  write  scenarios
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
More  does  not  mean  be)er
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
“I  get  paid  for  code  that  works,  not  for  tests,  so  my  philosophy  is  
to  test  as  li)le  as  possible  to  reach  a  given  level  of  confidence  ...
“I  suspect  this  level  of  confidence  is  high  compared  to  industry  
standards”
h)p://stackoverflow.com/quesBons/153234/how-­‐deep-­‐are-­‐your-­‐unit-­‐tests/153565#153565
Kent  Beck
It’s  about  confidence
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
How  many  guy  ropes?
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Clarity  over  detail
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
ImperaBve DeclaraBve
Avoid  incidental  details
Keep  it  focussed
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
TDD,  ATDD,  BDD,  SBE  …
h)p://lizkeogh.com/2011/06/27/atdd-­‐vs-­‐bdd-­‐and-­‐a-­‐po)ed-­‐history-­‐of-­‐some-­‐related-­‐stuff/
What’s  the  
difference  
between  TDD,  
ATDD,  BDD  
and  SbE?
They’re  
called  
different  
things
The  best  TDD  pracBBoners...
• Work  from  the  outside-­‐in,  i.e.  test-­‐first  
• Use  examples  to  clarify  their  requirements  
• Develop  and  use  a  ubiquitous  language
The  best  BDD  pracBBoners...
• Focus  on  value  
• Discover  examples  collabora7vely  
• Create  living  documenta7on
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
JUnit  or  Cucumber?
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
Take  aways
• BDD  is  about  collaboraBon  
• You  need  a  ubiquitous  language  
• Cucumber  can  power  conversaBon  
• and  produce  living  documentaBon  
• but  it’s  no  subsBtute  for  tesBng!
Seb  Rose  


Twi)er:     @sebrose  
Blog:        www.claysnow.co.uk  
E-­‐mail:     seb@cucumber.io
QuesBons?
Discount code at
pragprog.com
Java_One_25%_Off_Cuke
Valid for 1 month
@sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
h)ps://cemarking.net/wp-­‐content/uploads/2014/01/User-­‐Manual_featured.jpg
DocumentaBon
Acceptance
criteria
User Story
Examples
Feature: Team Scoring
Teams start with zero score.
Correct answer gets points depending on 

how difficult it is.
Scenario: Score starts at 0
Given I register a team
Then my score is 0
Scenario: Correct easy answer scores 10
Given I register a team
When I submit a correct easy answer
Then my score is 10
Scenario: Correct hard answer scores 50
Given I register a team
When I submit a correct hard answer
Then my score is 50
Step outcome
!Passed
" No exception thrown
!Pending
" Pending exception thrown
!Undefined
" No matching step definition found
!Failed
" Any other exception thrown
!Skipped
" Steps that follow a Pending, Undefined or Failed step
!Duplicate
" Step matches more than one step definition
@sebrose http://claysnow.co.uk
Scenario outcome
!Passed
" All steps passed
!Failed
" Any step failed
!Undefined
" No failed steps
" At least one undefined step
!Pending
" No failed or undefined steps
" At least one pending step
@sebrose http://claysnow.co.uk

More Related Content

What's hot (20)

PDF
BDD & Cucumber
Vladimir Arutin
 
PPTX
BDD testing with cucumber
Daniel Kummer
 
ODP
BDD with Cucumber
Knoldus Inc.
 
PDF
Cucumber ppt
Qwinix Technologies
 
ODP
Introduction to BDD
Knoldus Inc.
 
PPTX
Introduction to Behaviour Driven Development (BDD) and Cucumber with Java
Jawad Khan
 
PPTX
Automated Test Framework with Cucumber
Ramesh Krishnan Ganesan
 
PPTX
Cucumber presenation
Oussama BEN WAFI
 
PPT
Cucumber presentation
Akhila B
 
PPSX
Cucumber & gherkin language
selvanathankapilan
 
PPTX
Test automation with Cucumber-JVM
Alan Parkinson
 
PPT
Agile testing
Yogita patil
 
PPTX
Behavior driven development (bdd)
Rohit Bisht
 
PDF
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
PPTX
Track code quality with SonarQube - short version
Dmytro Patserkovskyi
 
PPTX
SonarQube - The leading platform for Continuous Code Quality
Larry Nung
 
PPTX
Express JS Middleware Tutorial
Simplilearn
 
PPTX
Selenium with java
Gousalya Ramachandran
 
PDF
An introduction to Behavior-Driven Development (BDD)
Suman Guha
 
PDF
Continuous Inspection of Code Quality: SonarQube
Emre Dündar
 
BDD & Cucumber
Vladimir Arutin
 
BDD testing with cucumber
Daniel Kummer
 
BDD with Cucumber
Knoldus Inc.
 
Cucumber ppt
Qwinix Technologies
 
Introduction to BDD
Knoldus Inc.
 
Introduction to Behaviour Driven Development (BDD) and Cucumber with Java
Jawad Khan
 
Automated Test Framework with Cucumber
Ramesh Krishnan Ganesan
 
Cucumber presenation
Oussama BEN WAFI
 
Cucumber presentation
Akhila B
 
Cucumber & gherkin language
selvanathankapilan
 
Test automation with Cucumber-JVM
Alan Parkinson
 
Agile testing
Yogita patil
 
Behavior driven development (bdd)
Rohit Bisht
 
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Track code quality with SonarQube - short version
Dmytro Patserkovskyi
 
SonarQube - The leading platform for Continuous Code Quality
Larry Nung
 
Express JS Middleware Tutorial
Simplilearn
 
Selenium with java
Gousalya Ramachandran
 
An introduction to Behavior-Driven Development (BDD)
Suman Guha
 
Continuous Inspection of Code Quality: SonarQube
Emre Dündar
 

Similar to Introduction to BDD with Cucumber for Java (20)

PDF
#NoEstimates does not mean "No estimates!" - Agile Cambridge 2015
Seb Rose
 
PDF
10 things about BDD, Cucumber and SpecFlow - Long Version 2016
Seb Rose
 
PDF
CouchDB - Local Web Platform
Chris Anderson
 
PDF
CouchDB Google
Steve Souders
 
PDF
Ruboto
Ehthisham Tk
 
PDF
JRuby on Rails - RoR's Simplicity Meets Java's Class (a case in point)
Darshan Karandikar
 
PDF
Open innovation in software means Open Source (2011 remix)
Bertrand Delacretaz
 
ZIP
Evaluating Methods to Rediscover Missing Web Pages from the Web Infrastructure
Martin Klein
 
PDF
JRuby, Ruby, Rails and You on the Cloud
Hiro Asari
 
PDF
Practice of Android Reverse Engineering
National Cheng Kung University
 
PPTX
What I Learned at Open Hack Naperville
Kevin Davis
 
PDF
Real world continuous delivery
Seb Rose
 
PDF
Hybrid Apps with Ionic Framework
Bramus Van Damme
 
PDF
儲かるドキュメント
Yoshiki Shibukawa
 
PDF
Building collaborative workflows for scientific data
Bruno Vieira
 
PDF
What would your own version of Ruby look like?
Hung Wu Lo
 
PDF
Collaborations in the Extreme: 
The rise of open code development in the scie...
Kelle Cruz
 
PDF
Open Innovation means Open Source
Bertrand Delacretaz
 
PDF
Devoxx France 2013 Cloud Best Practices
Eric Bottard
 
PPTX
Go for Rubyists. August 2018. RUG-B Meetup
Kirill Zonov
 
#NoEstimates does not mean "No estimates!" - Agile Cambridge 2015
Seb Rose
 
10 things about BDD, Cucumber and SpecFlow - Long Version 2016
Seb Rose
 
CouchDB - Local Web Platform
Chris Anderson
 
CouchDB Google
Steve Souders
 
Ruboto
Ehthisham Tk
 
JRuby on Rails - RoR's Simplicity Meets Java's Class (a case in point)
Darshan Karandikar
 
Open innovation in software means Open Source (2011 remix)
Bertrand Delacretaz
 
Evaluating Methods to Rediscover Missing Web Pages from the Web Infrastructure
Martin Klein
 
JRuby, Ruby, Rails and You on the Cloud
Hiro Asari
 
Practice of Android Reverse Engineering
National Cheng Kung University
 
What I Learned at Open Hack Naperville
Kevin Davis
 
Real world continuous delivery
Seb Rose
 
Hybrid Apps with Ionic Framework
Bramus Van Damme
 
儲かるドキュメント
Yoshiki Shibukawa
 
Building collaborative workflows for scientific data
Bruno Vieira
 
What would your own version of Ruby look like?
Hung Wu Lo
 
Collaborations in the Extreme: 
The rise of open code development in the scie...
Kelle Cruz
 
Open Innovation means Open Source
Bertrand Delacretaz
 
Devoxx France 2013 Cloud Best Practices
Eric Bottard
 
Go for Rubyists. August 2018. RUG-B Meetup
Kirill Zonov
 
Ad

More from Seb Rose (20)

PDF
AI and developer obsolescence - BCS 2025.pdf
Seb Rose
 
PDF
Software contracts - Global Enterprise Agile 2023.pdf
Seb Rose
 
PDF
Micro-service delivery - without the pitfalls
Seb Rose
 
PDF
DevSecOps - Agile Get-Together 2022.pdf
Seb Rose
 
PDF
Contract testing - Sealights 2022.pdf
Seb Rose
 
PDF
Example mapping - slice any story into testable examples - SoCraTes 2022.pdf
Seb Rose
 
PDF
Software testing - learning to walk again (expoQA22)
Seb Rose
 
PDF
DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021
Seb Rose
 
PDF
A brief history of requirements - Unicom 2022
Seb Rose
 
PDF
Example mapping (with builds) - ProductWorld 2022
Seb Rose
 
PDF
Example mapping - ProductWorld 2022
Seb Rose
 
PDF
No code, low code, machine code QA ATL 2021
Seb Rose
 
PDF
No code, low code, machine code QA ATL 2021
Seb Rose
 
PDF
No code, low code, machine code - Unicom 2021
Seb Rose
 
PDF
BDD: from soup to nuts - The Future of Work Scotland 2021
Seb Rose
 
PDF
Contrasting test automation and BDD - 2020
Seb Rose
 
PDF
Are BDD and test automation the same thing? Automation Guild 2021
Seb Rose
 
PDF
"Our BDDs are broken!" Lean Agile Exchange 2020
Seb Rose
 
PDF
User stories: from good intentions to bad advice - Agile Scotland 2019
Seb Rose
 
PDF
User stories: from good intentions to bad advice - Lean Agile Scotland 2019
Seb Rose
 
AI and developer obsolescence - BCS 2025.pdf
Seb Rose
 
Software contracts - Global Enterprise Agile 2023.pdf
Seb Rose
 
Micro-service delivery - without the pitfalls
Seb Rose
 
DevSecOps - Agile Get-Together 2022.pdf
Seb Rose
 
Contract testing - Sealights 2022.pdf
Seb Rose
 
Example mapping - slice any story into testable examples - SoCraTes 2022.pdf
Seb Rose
 
Software testing - learning to walk again (expoQA22)
Seb Rose
 
DevSecOps - Unicom Agile and DevOps Expo (Adaptive Challenges) 2021
Seb Rose
 
A brief history of requirements - Unicom 2022
Seb Rose
 
Example mapping (with builds) - ProductWorld 2022
Seb Rose
 
Example mapping - ProductWorld 2022
Seb Rose
 
No code, low code, machine code QA ATL 2021
Seb Rose
 
No code, low code, machine code QA ATL 2021
Seb Rose
 
No code, low code, machine code - Unicom 2021
Seb Rose
 
BDD: from soup to nuts - The Future of Work Scotland 2021
Seb Rose
 
Contrasting test automation and BDD - 2020
Seb Rose
 
Are BDD and test automation the same thing? Automation Guild 2021
Seb Rose
 
"Our BDDs are broken!" Lean Agile Exchange 2020
Seb Rose
 
User stories: from good intentions to bad advice - Agile Scotland 2019
Seb Rose
 
User stories: from good intentions to bad advice - Lean Agile Scotland 2019
Seb Rose
 
Ad

Recently uploaded (20)

PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Biography of Daniel Podor.pdf
Daniel Podor
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
July Patch Tuesday
Ivanti
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 

Introduction to BDD with Cucumber for Java

  • 1. Seb  Rose   [email protected] @sebrose                                                                                                                                                                                                                                                                                                                                                                h0p://cucumber.io An  Introduc9on  to     Behaviour  Driven  Development   with   Cucumber  for  Java
  • 2. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Agenda -­‐ What  is  BDD?   -­‐ What  is  Cucumber?   -­‐ Demo  Cucumber  for  Java   -­‐ Cucumber  variants   -­‐ Pu@ng  it  all  together
  • 3. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io What  is  BDD? Behaviour Driven DevelopmentDesign
  • 4. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io BDD   is   a   second-­‐generaBon,   outside-­‐in,   pull-­‐based,   mulBple-­‐stakeholder,   mulBple-­‐scale,   high-­‐automaBon,   agile  methodology.     It   describes   a   cycle   of   interacBons   with   well-­‐defined   outputs,   resulBng   in   the   delivery   of   working,   tested   soJware  that  ma)ers.   Dan  North h)p://skillsma)er.com/podcast/java-­‐jee/how-­‐to-­‐sell-­‐bdd-­‐to-­‐the-­‐business BDD  defined
  • 5. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io The  power  of  “should” -­‐Diverts  developers  from  their  distaste  for  tesBng   -­‐Encourages  people  to  ask  “Should  it  really?”
  • 6. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Deliberate  discovery “…  during  an  incepBon,  when  we  are  most   ignorant  about  most  aspects  of  the  project,   the  best  use  we  can  possibly  make  of  the  Bme   available  is  to  a)empt  to  idenBfy  and  reduce   our  ignorance  …”   Dan  North h)p://dannorth.net/2010/08/30/introducing-­‐deliberate-­‐discovery/
  • 7. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Ubiquitous  language “The  pracBce  of  building   up  a  common,  rigorous   language  between   developers  and  users”   MarBn  Fowler
  • 8. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io The  3  Amigos The one where... User  stories  &   acceptance   criteria Examples Open   quesBons Domain   learning
  • 9. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Example  mapping Acceptance Criterion (Rule) User Story Example Open Question Acceptance Criterion (Rule) Acceptance Criterion (Rule) Example Example Example Example Example
  • 10. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Important  conversaBons having  conversaBons     is  more  important  than     capturing  conversaBons     is  more  important  than     automa.ng  conversaBons   Liz  Keogh h)p://lizkeogh.com/2014/01/22/using-­‐bdd-­‐with-­‐legacy-­‐systems/
  • 11. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Living  documentaBon a.k.a  Executable  specificaBon Living  documentaBon  is  a  reliable  and   authoritaBve  source  of  informaBon  on  system   funcBonality,  which  anyone  can  easily  access.     It  is  as  reliable  as  the  code,  but  much  easier  to   read  and  understand.   Gojko  Adzic h)p://specificaBonbyexample.com/key_ideas.html
  • 12. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io What  BDD  is  not…. -­‐ Using  “Given/When/Then”   -­‐ The  responsibility  of  testers   -­‐ An  alternaBve  to  manual  tesBng
  • 13. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io What  is  Cucumber? Features -Scenarios   -­‐Steps -Gherkin Glue  code -Step  definiBons -Ruby   -Java   -C#  &  others ApplicaBon
  • 14. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Feature: Team Scoring Teams start with zero score. Correct answer gets points depending on 
 how difficult it is. Scenario: New teams should not have scored yet Given I register a team Then my score is 0 Scenario: Correctly answering a question scores points Given I register a team When I submit a correct answer Then my score is 10
  • 15. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Feature:  Feature  name   Descrip8on  of  feature  goes  here   Scenario:  Scenario  name   Descrip8on  of  scenario  goes  here   Given  a  certain  context   When  something  happens   Then  an  outcome   And  something  else   But  not  this  though   Scenario:  Another  scenario  name   ... Gherkin  fundamentals
  • 16. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Given(/^I register a team$/) do # Glue code goes here end Ruby
  • 17. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io import cucumber.api.java.en.*; public class MyStepDefinitions { @Given("^I register a team$") public void iRegisterATeam() throws Throwable { // Glue code goes here } } Java
  • 18. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io
  • 19. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Cucumber  variants • Ruby   • C#  (Specflow)   • Java  (&  other  JVM  languages)   • Javascript   • PHP   • Python   • C++
  • 20. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Given/When/Then  namespaces Global  namespace     -­‐  Given/When/Then  interchangeable Separate  namespaces     -­‐  Given/When/Then  disBnct   -­‐  And/But  bind  to  preceding  namespace   -­‐  [StepDefiniBon]  for  compaBbility
  • 21. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Binding  &  test  frameworks Behind  the  scenes   -­‐  may  need  to  specify  paths   -­‐  select  required  plugin(s) Some  magic  code  generaBon   -­‐  NUnit  by  default   -­‐  configuraBon  changes  for  others   -­‐  several  output  opBons
  • 22. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Sharing  data  between  steps Varies  by  implementaBon   -­‐  Ruby,  Javascript:  World  object   -­‐  Java:  Dependency  InjecBon Context  object(s)   -­‐  Injected   -­‐  Scenario   -­‐  Feature
  • 23. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Hooks Before  &  AJer   Ruby:  Around,  AJerStep Before  &  AJer   BeforeStep  &  AJerStep   BeforeFeature  &  AJerFeature   BeforeTestRun  &  AJerTestRun   BeforeScenarioBlock  &   AJerScenarioBlock
  • 24. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Pu@ng  it  all  together SoJware  development  is  hard.   Understanding  what  your     methods  and  tools     are  good  for   can  make  it  easier.
  • 25. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Tools  are  not  essenBal
  • 26. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io BDD   is   a   second-­‐generaBon,   outside-­‐in,   pull-­‐based,   mulBple-­‐stakeholder,   mulBple-­‐scale,   high-­‐automaBon,   agile  methodology.     It   describes   a   cycle   of   interacBons   with   well-­‐defined   outputs,   resulBng   in   the   delivery   of   working,   tested   soJware  that  ma)ers.   Dan  North h)p://skillsma)er.com/podcast/java-­‐jee/how-­‐to-­‐sell-­‐bdd-­‐to-­‐the-­‐business BDD  redefined
  • 27. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io h)ps://cucumber.pro/blog/2014/03/03/the-­‐worlds-­‐most-­‐misunderstood-­‐collaboraBon-­‐tool.html When  you  do  BDD/SpecificaBon  by  Example  and  Outside-­‐in,   regression   tests   fall   out   at   the   other   end.   They   are   a   by-­‐ product  of  those  acBviBes.  TesBng  isn't  the  acBvity  itself.   Cucumber  is  first  a  foremost  a  collaboraBon  tool  that  aims  to   bring   a   common   understanding   to   soJware   teams   -­‐   across   roles.   Aslak  Hellesøy It’s  about  collaboraBon
  • 28. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io We  sBll  need  testers
  • 29. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io h)p://claysnow.co.uk/architectural-­‐alignment-­‐and-­‐test-­‐induced-­‐design-­‐damage-­‐fallacy/ Test  =  check  +  explore
  • 30. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io So  much  can  go  wrong!
  • 31. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io h)p://1.bp.blogspot.com/_YzKCMr-­‐tcMM/TFLIGeqTJfI/AAAAAAAAARQ/AhNW62KX5EA/s1600/cartoon6.jpg AutomaBon  is  development
  • 32. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Understand  designs Features -Scenarios   -­‐Steps -Gherkin Glue  code -Step  definiBons -Ruby   -Java   -C#  &  others ApplicaBon Support   code
  • 33. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io This  page  intenBonally  blank. <role>  will  write  scenarios
  • 34. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io More  does  not  mean  be)er
  • 35. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io “I  get  paid  for  code  that  works,  not  for  tests,  so  my  philosophy  is   to  test  as  li)le  as  possible  to  reach  a  given  level  of  confidence  ... “I  suspect  this  level  of  confidence  is  high  compared  to  industry   standards” h)p://stackoverflow.com/quesBons/153234/how-­‐deep-­‐are-­‐your-­‐unit-­‐tests/153565#153565 Kent  Beck It’s  about  confidence
  • 36. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io How  many  guy  ropes?
  • 37. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Clarity  over  detail
  • 38. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io ImperaBve DeclaraBve Avoid  incidental  details Keep  it  focussed
  • 39. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io TDD,  ATDD,  BDD,  SBE  …
  • 41. The  best  TDD  pracBBoners... • Work  from  the  outside-­‐in,  i.e.  test-­‐first   • Use  examples  to  clarify  their  requirements   • Develop  and  use  a  ubiquitous  language
  • 42. The  best  BDD  pracBBoners... • Focus  on  value   • Discover  examples  collabora7vely   • Create  living  documenta7on
  • 43. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io JUnit  or  Cucumber?
  • 44. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io Take  aways • BDD  is  about  collaboraBon   • You  need  a  ubiquitous  language   • Cucumber  can  power  conversaBon   • and  produce  living  documentaBon   • but  it’s  no  subsBtute  for  tesBng!
  • 45. Seb  Rose   
 Twi)er:     @sebrose   Blog:       www.claysnow.co.uk   E-­‐mail:     [email protected] QuesBons? Discount code at pragprog.com Java_One_25%_Off_Cuke Valid for 1 month
  • 46. @sebrose                                                                                                                                                                                                                                                                                                                                                                h)p://cucumber.io h)ps://cemarking.net/wp-­‐content/uploads/2014/01/User-­‐Manual_featured.jpg DocumentaBon
  • 47. Acceptance criteria User Story Examples Feature: Team Scoring Teams start with zero score. Correct answer gets points depending on 
 how difficult it is. Scenario: Score starts at 0 Given I register a team Then my score is 0 Scenario: Correct easy answer scores 10 Given I register a team When I submit a correct easy answer Then my score is 10 Scenario: Correct hard answer scores 50 Given I register a team When I submit a correct hard answer Then my score is 50
  • 48. Step outcome !Passed " No exception thrown !Pending " Pending exception thrown !Undefined " No matching step definition found !Failed " Any other exception thrown !Skipped " Steps that follow a Pending, Undefined or Failed step !Duplicate " Step matches more than one step definition @sebrose http://claysnow.co.uk
  • 49. Scenario outcome !Passed " All steps passed !Failed " Any step failed !Undefined " No failed steps " At least one undefined step !Pending " No failed or undefined steps " At least one pending step @sebrose http://claysnow.co.uk