SlideShare a Scribd company logo
Behaviour Driven Development with   Java Nikolay Vasilev 15 July 2011
Content What BDD is? Jbehave JBehave and Selenium Jbehave – Pros and Cons Questions and Answers References
BDD
Test-Driven Development (TDD) Approach for developing software by writing tests before writing the code being tested
Test-Driven Development (TDD) Facilitates Software Design Express Software Behaviour Documents the Code
Unit Testing A form of TDD Meets developer’s expectations for the code behaviour Fragile – Too coupled to the implementation Should meet user’s expectations
User’s Expectations Use Cases  User Stories  preferred in Agile projects Both of them have no validating mechanisms that the code meets user’s expectations
Testing Types and Expectations Application Levels   Testing Type Expectations   UI / Presentation / … Controls / Services / … Classes / Models / … Code Meets Customer’s Expectations Code Meets Programmer’s Expectations Unit Testing BDD Selenium
DDD and Ubiquitous Language Domain Driven Design Approach to developing software for complex needs by deeply connecting the implementation to an evolving model of the core business concepts Ubiquitous Language (UL) " A language structured around the domain model and used by all team members to connect all the activities of the team with the software " – Domain  Driven Design by Eric Evans.
Executable Documentation The system requirements are usually expressed by textual documentation In the ideal world the documentation uses UL If this documentation was executable, it would be perfect! It would assure that the code continues to meet the expectations in long term
Behaviour Driven Design A TDD approach It is an executable documentation Helps for UL development and usage Clears out the misunderstandings between customers, domain experts, developers, QA team etc. Can be used by everybody involved in a project
BDD as Stories and Behaviour BDD can be used to express Stories and Behaviour Stories Correspond to User Stories Express application behaviour at high level Stories framework needed (eventually) Behaviour (or Spec) Corresponds to expectations at class level Expresses behaviour at service/component level
Stories and Behaviour User Stories Series of acceptance criteria  Called  scenarios Each scenario has  givens ,  events  and  outcomes Used in Agile projects Behaviour Expressed as a test method It defines what the application  should  /  shouldn’t  do
A Story Structure Narrative  As a  [some_role_here] I want  [some_feature_here] So that  [behefit/value_of_the_feature_here] Scenario(s)   (this is acceptance criteria) Given  [some_initial_condition(s)] When  [event(s)_occurs] Then  [ensure_some_outcome(s)]
BDD Process Exercise expectations against Matches to Customer QA Domain Expert Developer
BDD Process
BDD Process Create scenarios for expected features Then follow the process: For each scenario describing a feature Run the scenario – it fails (go  red ) Define the first step – go  red Write down the application code getting the step to pass – go  green Refactor  the code and repeat steps 4 & 5 for each step until 6 The scenario passes – go  green Refactor  the application code
BDD Tools C – Cspec C++ – CppSpec, Spec-CPP .Net – NBehave, NSpecify, SpecFlow Groovy – GSpec, easyb, Cuke4Duke PHP – PHPSpec Python – Specipy Ruby – RSpec, Shoulda, Cucumber More…
BDD Tools (Java Related) JBehave  – Java annotations based, Test frameworks agnostic Cuke4duke  – Cucumber support for JVM JDave  – RSpec (Ruby) inspired, Mojo 2 & Hamcrest based beanSpec  – Java based easyb  – Java based, Specifications written in Groovy instinct  – BDD framework for Java, providing annotations for contexts. Inspired by Rspec BDoc  - Extracts behaviour from unit tests
JBehave
JBehave Open Source Java-based BDD Framework Created by Dan North (2003) to compare BDD to TDD Current version 3.4.2 Components JBehave Main JBehave Web
JBehave - Features Pure Java implementation Text-based user stories Annotation-based binding of textual steps to Java methods DI support (Spring, Guice, Pico, Weld) Story reporting (HTML, TXT, XML) User stories localization IDE integration Ant and Maven integration Test frameworks agnostic (JUnit, hamcrest, etc.)
JBehave Web - Features Extension of JBehave providing web integration layer for BDD Features JBehave Queue  – allows generic stories to be run asynchronously  Web Runner  – allows generic stories to be run synchronously Selenium Integration  – automation of stories for web apps using Selenium
JBehave – Five Steps Overview Write a story Map steps to Java Configure Stories Run Stories View Reports
JBehave – Five Steps Overview Step 1 – Write a story Narrative : In order to  calculate BMI with ease As a  doctor I want to  have BMI Calculator application Meta : @author Nikolay Vasilev @bg-jug Scenario : Simple BMI calculator validation Given  a body mass index calculator When  a patient's is with mass 77 kg and height 1.75 m Then  patient's body mass index is 25.14285659790039
JBehave – Five Steps Overview Step 2 – Map steps to Java
JBehave – Five Steps Overview Step 3 – Configure stories
JBehave – Five Steps Overview Step 4 – Run stories with:
JBehave – Five Steps Overview Step 5 – View Reports (HTML, TXT, XML)
JBehave – Use Case Body Mass Index Calculator and Classifier Domain Classes
JBehave – Use Case BMICalculator  component Computes BMI by the formula: Where BMI  – body mass index W  – a person’s mass in kilograms h  – a person’s height in meters
JBehave – Use Case WeightClassifier  component
JBehave Stories Plain-text stories Consists of  narrative  and multiple  scenarios Usually stored as  .story  file, but this is configurable Narrative Optional As a, In order to, I want to A scenario consists of: Given, When, Then And   maps to any of them Possible use of  When   after  Then Scenarios could depend on others scenario GivenScenarios Comments  ( !-- )
JBehave Steps Declared as Java annotations Steps annotations @Given, @When, @Then Lifecycle annotations  @BeforeStory, @AfterStory @BeforeScenario, @AfterScenario Pending steps @Pending  keyword
JBehave Steps Step annotations take regex See Code Example Alias(es) – mapping  various text strings to one method  @Alias, @Aliases See Code Example Parameter Injection Captured values are converted to method parameters @Named   – Explicit mapping of values to parameters See Code Example
JBehave Configuration Everything is configurable (powerful) Everything has defaults (makes life easy) Main Configuration How to load stories (classpath, file, etc.) Story file naming and parsing configuration Error strategy and Pending error strategy How to handle failure and missing steps Step Configuration Parameter Converters
JBehave Configuration Embedder  and  Embeddable
JBehave Configuration Jbehave provides two Embeddable implementations ConfigurableEmbedder InjectableEmbedder ( example  AnnotatedEmbedder ) JUnit-enabled Embeddables Ran like JUnit tests JUnitStory   -  one-to-one mapping with the textual story JUnitStories   -  many-to-one mapping  Exntending  Embedder EclipseEmbedder   example
JBehave – Advanced Parameterized Scenarios Examples:  - required in the story Followed by table of parameters The mapped parameters should be surrounded by ' < ‘ and ' > ‘ in the story Table examples require  named parameters  for the step candidates to be matched to the Java methods The step annotation pattern must hold the verbatim textual step The tables could be loaded from external resources
JBehave – Advanced Non-English Keywords Tabular parameters Multiline values Example : Given  tab  e|---------------------------------  B|---------------------------------  G|---------------------------------  D|----------0--0-------------------  A|-0--2--3----------2--0-----0--0–  E|------------------------3-------- When  the guitar plays  Then  the following notes will be played  A0 A2 A3 D0 D0 A2 A0 E3 A0 A0
JBehave – Advanced Meta information Meta Followed by name value properties separated by  @ Example: Meta filtering Used for selecting of stories Meta @author  Nikolay Vasilev @organization  Bulgarian Java Users Group -author *Vasilev
JBehave – Advanced Ant tasks and Maven plugin Integration with Spring, Pico, Guice Reporting options  Console, Text, HTML, XML Default reports location in a Maven project: ${project.dir}/target/jbehave Example Test integration (JUnit and TestNG) See  AnnotatedEmbedder  example
JBehave Reporting Options Reports HTML Report
JBehave Reporting Options Failing Story HTML Report
JBehave Reporting Options Pending Steps Story HTML Report
JBehave Reporting Options Parametrized Story HTML Report
JBehave – Eclipse Plugin Home Page   Status: In development Non-trivial installation (next slides) Not very rich functionality but makes the life easier Provides  Basic highlighting On match, the step in the story is linked to the mapped method Certain autocomplete when writing stories
JBehave – Eclipse Plugin Example Keywords highlighting “ Jumping” from story to Steps class Autocomplete
JBehave – Install Eclipse Plugin Download the plugin
JBehave – Install Eclipse Plugin Eclipse > File > Import
JBehave – Install Eclipse Plugin Existing Projects into Workspace
JBehave – Install Eclipse Plugin Select archive file: > Browse
JBehave – Install Eclipse Plugin Select archive file > Open
JBehave – Install Eclipse Plugin Select archive file:
JBehave – Install Eclipse Plugin Finish
JBehave – Install Eclipse Plugin Project Editor > Select the new project
JBehave – Install Eclipse Plugin File > Export
JBehave – Install Eclipse Plugin Select > Deployable plug-ins and frag…
JBehave – Install Eclipse Plugin Select > Deployable plug-ins and frag…
JBehave – Install Eclipse Plugin Select the Plug-in & Chose Install into host
JBehave – Install Eclipse Plugin Restart Eclipse (Chose ‘Yes’)
JBehave – Install Eclipse Plugin The story files are with different icon  
JBehave – Install Eclipse Plugin Not “recognized” stories > Select + Right Click > Open With > Behavior Editor
JBehave – Install Eclipse Plugin Now the keywords are highlighted
Jbehave and Selenium
JBehave and Selenium Selenium A suite of tools to automate web app testing across many platforms.   Abstracts away the interaction with the web layer (browser/server) Java, Perl, C#, C, etc. Selenium Object Tested WebApp Selenium RC Server Browsers
JBehave and Selenium Selenium would let us focus on testing the web-app functionality Although, steps classes get cluttered by selenium calls Steps Selenium Object Tested WebApp Selenium RC Server Browsers Stories
JBehave and Selenium JBehave and Selenium First thought - Steps will interact with the selenium object from the steps classes Steps Selenium Object Tested WebApp Selenium RC Server Browsers Stories
JBehave and Selenium Page Objects Pattern Page object represent the services offered by a page Hides the knowledge of the page structure from the developer Steps Selenium Object Tested WebApp Selenium RC Server Browsers Stories Page Object
JBehave and Selenium Rules of  Thumb Keep assertions in the steps mapping classes  Keep selenium interaction in the page objects Stories should address the  functionality  which the pages offer
JBehave and Selenium What do we need to integrate JBehave and Selenium SeleniumConfiguration  (part of JBehave Web) @BeforeScenario, @AfterScenario  steps Responsible of start/stop selenium object Pages and Steps implementation Running selenium tests in an automated way (maven –  integration-test  phase) Tip:  Configure  Firefox for testing with  Selenium
Use Case – Web Testing Web app for our Use Case 2 JSPs – one for main form, another for result In order to run it are required: Run the web app on a web server Run the Selenium RC server with the selenium profile (see tip from prev. slide) Execute  WebBmiCalculatorStories  embedder as JUnit test
Use Case – Web Testing Main form
Use Case – Web Testing Result page
Use Case – Web Testing The main form is also error page
JBehave - Pros and Cons
Questions and Answers
Use Case & Examples Code Use Case Code –  Consists of 3 Maven 2 projects jug-bg-bdd-domain Domain Classes of the Application jug-bg-bdd-jbehave JBehave Examples (depending on the first project) jug-bg-bdd-web JBehave & Selenium Examples (depending on the first project)
Use Case & Examples Code Source Code could be found on: http://code.google.com/p/bg-jug-resource-repository/
References BDD Wiki Jbehave JBehave Tutorial Dan North –  Introducing BDD Dan North -  What’s in a Story? [pdf]  BDD in Java and Groovy [pdf]  TDD Beyond  Junit BDD in a Nutshell
References Ryan Greenhall –  BDD by  Example Localizing JBehave Scenarios Eric Evans - &quot;Domain-Driven Design: Tackling Complexity in the Heart of Software&quot;,  Addison-Wesley JBehave Site :: Dependency Injection JBehave + Spring + Selenium Example
References Selenium Project   Page Objects Pattern Creating Firefox Profile for Selenium RC  Tests JBehave Site :: Using Selenium BDD with JBehave Web 3, Selenium and Maven 2 for OS X Leopard Nice JBehave + Selenium + Maven Example Selenium Tutorial to set up a Selenium Grid
Thank you for your attention!

More Related Content

What's hot (20)

PDF
Selenium with Cucumber
Knoldus Inc.
 
ODP
Introduction to BDD
Knoldus Inc.
 
PDF
An introduction to Behavior-Driven Development (BDD)
Suman Guha
 
PPTX
What Is Cucumber?
QATestLab
 
PPTX
Test Automation Framework with BDD and Cucumber
Rhoynar Software Consulting
 
PPT
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
PPTX
Behavior driven development (bdd)
Rohit Bisht
 
PPTX
BDD testing with cucumber
Daniel Kummer
 
PPTX
Automation test framework with cucumber – BDD
123abcda
 
PDF
Successfully Implementing BDD in an Agile World
SmartBear
 
PDF
Bdd Introduction
Skills Matter
 
PPTX
Bdd – with cucumber and gherkin
Arati Joshi
 
PPTX
Track code quality with SonarQube
Dmytro Patserkovskyi
 
PPTX
Behavior Driven Development
Liz Keogh
 
ODP
Test Automation Framework using Cucumber BDD overview (part 1)
Mindfire Solutions
 
PPT
Selenium Concepts
Swati Bansal
 
PPTX
Selenium WebDriver training
Vijay Krishnan Ramaswamy
 
PPTX
BDD presentation
temebele
 
PDF
BDD in Action – principles, practices and real-world application
John Ferguson Smart Limited
 
PPTX
Hybrid automation framework
doai tran
 
Selenium with Cucumber
Knoldus Inc.
 
Introduction to BDD
Knoldus Inc.
 
An introduction to Behavior-Driven Development (BDD)
Suman Guha
 
What Is Cucumber?
QATestLab
 
Test Automation Framework with BDD and Cucumber
Rhoynar Software Consulting
 
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
Behavior driven development (bdd)
Rohit Bisht
 
BDD testing with cucumber
Daniel Kummer
 
Automation test framework with cucumber – BDD
123abcda
 
Successfully Implementing BDD in an Agile World
SmartBear
 
Bdd Introduction
Skills Matter
 
Bdd – with cucumber and gherkin
Arati Joshi
 
Track code quality with SonarQube
Dmytro Patserkovskyi
 
Behavior Driven Development
Liz Keogh
 
Test Automation Framework using Cucumber BDD overview (part 1)
Mindfire Solutions
 
Selenium Concepts
Swati Bansal
 
Selenium WebDriver training
Vijay Krishnan Ramaswamy
 
BDD presentation
temebele
 
BDD in Action – principles, practices and real-world application
John Ferguson Smart Limited
 
Hybrid automation framework
doai tran
 

Similar to BDD with JBehave and Selenium (20)

PPT
Introduction to Behavior Driven Development
Robin O'Brien
 
PDF
Behavior Driven Development - WPC 2011
Fabio Armani
 
PDF
Behaviour Driven Development
Ben Goldin
 
KEY
Bahaviour Driven Development
buildmaster
 
PPTX
Bdd test automation analysis
ssuser2e8d4b
 
PDF
jSession#6 - Adam Bieńkowski - JGiven - BDD testing in plain Java
jSession
 
PPTX
Topic tdd-and-bdd b4usolution
Hoa Le
 
PPTX
Current State of BDD Testing Tools
Jonathan Miller Kauffman
 
KEY
TorontoRb Intro to BDD
nunick
 
PDF
Intro to TDD & BDD
devObjective
 
PDF
ITB2015 - Behavior Driven Development, Automation and Continuous Integration
Ortus Solutions, Corp
 
PDF
2015 in tothebox-introtddbdd
ColdFusionConference
 
PPTX
Jbehave selenium
Vadim Goncharenko
 
PPTX
So What Do Cucumbers Have To Do With Testing
sjmarsh
 
PDF
Dont be fooled with BDD, automation engineer! ;)
Iakiv Kramarenko
 
PDF
Dont be fooled with BDD, automation engineer! ;)
automician
 
PDF
Iakiv Kramarenko - Don't be fooled with BDD, automation engineer
Ievgenii Katsan
 
PPT
Behavior Driven Development by Example
Nalin Goonawardana
 
PPTX
Behavior-Driven Development (BDD) and Its Impact on Software Testing.pptx
digitalmuskan2244
 
PDF
Behavior Driven Education: A Story of Learning ROR
SmartLogic
 
Introduction to Behavior Driven Development
Robin O'Brien
 
Behavior Driven Development - WPC 2011
Fabio Armani
 
Behaviour Driven Development
Ben Goldin
 
Bahaviour Driven Development
buildmaster
 
Bdd test automation analysis
ssuser2e8d4b
 
jSession#6 - Adam Bieńkowski - JGiven - BDD testing in plain Java
jSession
 
Topic tdd-and-bdd b4usolution
Hoa Le
 
Current State of BDD Testing Tools
Jonathan Miller Kauffman
 
TorontoRb Intro to BDD
nunick
 
Intro to TDD & BDD
devObjective
 
ITB2015 - Behavior Driven Development, Automation and Continuous Integration
Ortus Solutions, Corp
 
2015 in tothebox-introtddbdd
ColdFusionConference
 
Jbehave selenium
Vadim Goncharenko
 
So What Do Cucumbers Have To Do With Testing
sjmarsh
 
Dont be fooled with BDD, automation engineer! ;)
Iakiv Kramarenko
 
Dont be fooled with BDD, automation engineer! ;)
automician
 
Iakiv Kramarenko - Don't be fooled with BDD, automation engineer
Ievgenii Katsan
 
Behavior Driven Development by Example
Nalin Goonawardana
 
Behavior-Driven Development (BDD) and Its Impact on Software Testing.pptx
digitalmuskan2244
 
Behavior Driven Education: A Story of Learning ROR
SmartLogic
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Python basic programing language for automation
DanialHabibi2
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Ad

BDD with JBehave and Selenium

  • 1. Behaviour Driven Development with Java Nikolay Vasilev 15 July 2011
  • 2. Content What BDD is? Jbehave JBehave and Selenium Jbehave – Pros and Cons Questions and Answers References
  • 3. BDD
  • 4. Test-Driven Development (TDD) Approach for developing software by writing tests before writing the code being tested
  • 5. Test-Driven Development (TDD) Facilitates Software Design Express Software Behaviour Documents the Code
  • 6. Unit Testing A form of TDD Meets developer’s expectations for the code behaviour Fragile – Too coupled to the implementation Should meet user’s expectations
  • 7. User’s Expectations Use Cases User Stories preferred in Agile projects Both of them have no validating mechanisms that the code meets user’s expectations
  • 8. Testing Types and Expectations Application Levels Testing Type Expectations UI / Presentation / … Controls / Services / … Classes / Models / … Code Meets Customer’s Expectations Code Meets Programmer’s Expectations Unit Testing BDD Selenium
  • 9. DDD and Ubiquitous Language Domain Driven Design Approach to developing software for complex needs by deeply connecting the implementation to an evolving model of the core business concepts Ubiquitous Language (UL) &quot; A language structured around the domain model and used by all team members to connect all the activities of the team with the software &quot; – Domain Driven Design by Eric Evans.
  • 10. Executable Documentation The system requirements are usually expressed by textual documentation In the ideal world the documentation uses UL If this documentation was executable, it would be perfect! It would assure that the code continues to meet the expectations in long term
  • 11. Behaviour Driven Design A TDD approach It is an executable documentation Helps for UL development and usage Clears out the misunderstandings between customers, domain experts, developers, QA team etc. Can be used by everybody involved in a project
  • 12. BDD as Stories and Behaviour BDD can be used to express Stories and Behaviour Stories Correspond to User Stories Express application behaviour at high level Stories framework needed (eventually) Behaviour (or Spec) Corresponds to expectations at class level Expresses behaviour at service/component level
  • 13. Stories and Behaviour User Stories Series of acceptance criteria Called scenarios Each scenario has givens , events and outcomes Used in Agile projects Behaviour Expressed as a test method It defines what the application should / shouldn’t do
  • 14. A Story Structure Narrative As a [some_role_here] I want [some_feature_here] So that [behefit/value_of_the_feature_here] Scenario(s) (this is acceptance criteria) Given [some_initial_condition(s)] When [event(s)_occurs] Then [ensure_some_outcome(s)]
  • 15. BDD Process Exercise expectations against Matches to Customer QA Domain Expert Developer
  • 17. BDD Process Create scenarios for expected features Then follow the process: For each scenario describing a feature Run the scenario – it fails (go red ) Define the first step – go red Write down the application code getting the step to pass – go green Refactor  the code and repeat steps 4 & 5 for each step until 6 The scenario passes – go green Refactor  the application code
  • 18. BDD Tools C – Cspec C++ – CppSpec, Spec-CPP .Net – NBehave, NSpecify, SpecFlow Groovy – GSpec, easyb, Cuke4Duke PHP – PHPSpec Python – Specipy Ruby – RSpec, Shoulda, Cucumber More…
  • 19. BDD Tools (Java Related) JBehave – Java annotations based, Test frameworks agnostic Cuke4duke – Cucumber support for JVM JDave – RSpec (Ruby) inspired, Mojo 2 & Hamcrest based beanSpec – Java based easyb – Java based, Specifications written in Groovy instinct – BDD framework for Java, providing annotations for contexts. Inspired by Rspec BDoc - Extracts behaviour from unit tests
  • 21. JBehave Open Source Java-based BDD Framework Created by Dan North (2003) to compare BDD to TDD Current version 3.4.2 Components JBehave Main JBehave Web
  • 22. JBehave - Features Pure Java implementation Text-based user stories Annotation-based binding of textual steps to Java methods DI support (Spring, Guice, Pico, Weld) Story reporting (HTML, TXT, XML) User stories localization IDE integration Ant and Maven integration Test frameworks agnostic (JUnit, hamcrest, etc.)
  • 23. JBehave Web - Features Extension of JBehave providing web integration layer for BDD Features JBehave Queue – allows generic stories to be run asynchronously Web Runner – allows generic stories to be run synchronously Selenium Integration – automation of stories for web apps using Selenium
  • 24. JBehave – Five Steps Overview Write a story Map steps to Java Configure Stories Run Stories View Reports
  • 25. JBehave – Five Steps Overview Step 1 – Write a story Narrative : In order to calculate BMI with ease As a doctor I want to have BMI Calculator application Meta : @author Nikolay Vasilev @bg-jug Scenario : Simple BMI calculator validation Given a body mass index calculator When a patient's is with mass 77 kg and height 1.75 m Then patient's body mass index is 25.14285659790039
  • 26. JBehave – Five Steps Overview Step 2 – Map steps to Java
  • 27. JBehave – Five Steps Overview Step 3 – Configure stories
  • 28. JBehave – Five Steps Overview Step 4 – Run stories with:
  • 29. JBehave – Five Steps Overview Step 5 – View Reports (HTML, TXT, XML)
  • 30. JBehave – Use Case Body Mass Index Calculator and Classifier Domain Classes
  • 31. JBehave – Use Case BMICalculator component Computes BMI by the formula: Where BMI – body mass index W – a person’s mass in kilograms h – a person’s height in meters
  • 32. JBehave – Use Case WeightClassifier component
  • 33. JBehave Stories Plain-text stories Consists of narrative and multiple scenarios Usually stored as .story file, but this is configurable Narrative Optional As a, In order to, I want to A scenario consists of: Given, When, Then And maps to any of them Possible use of When after Then Scenarios could depend on others scenario GivenScenarios Comments ( !-- )
  • 34. JBehave Steps Declared as Java annotations Steps annotations @Given, @When, @Then Lifecycle annotations @BeforeStory, @AfterStory @BeforeScenario, @AfterScenario Pending steps @Pending keyword
  • 35. JBehave Steps Step annotations take regex See Code Example Alias(es) – mapping various text strings to one method @Alias, @Aliases See Code Example Parameter Injection Captured values are converted to method parameters @Named – Explicit mapping of values to parameters See Code Example
  • 36. JBehave Configuration Everything is configurable (powerful) Everything has defaults (makes life easy) Main Configuration How to load stories (classpath, file, etc.) Story file naming and parsing configuration Error strategy and Pending error strategy How to handle failure and missing steps Step Configuration Parameter Converters
  • 38. JBehave Configuration Jbehave provides two Embeddable implementations ConfigurableEmbedder InjectableEmbedder ( example AnnotatedEmbedder ) JUnit-enabled Embeddables Ran like JUnit tests JUnitStory - one-to-one mapping with the textual story JUnitStories - many-to-one mapping Exntending Embedder EclipseEmbedder example
  • 39. JBehave – Advanced Parameterized Scenarios Examples: - required in the story Followed by table of parameters The mapped parameters should be surrounded by ' < ‘ and ' > ‘ in the story Table examples require named parameters for the step candidates to be matched to the Java methods The step annotation pattern must hold the verbatim textual step The tables could be loaded from external resources
  • 40. JBehave – Advanced Non-English Keywords Tabular parameters Multiline values Example : Given tab e|--------------------------------- B|--------------------------------- G|--------------------------------- D|----------0--0------------------- A|-0--2--3----------2--0-----0--0– E|------------------------3-------- When the guitar plays Then the following notes will be played A0 A2 A3 D0 D0 A2 A0 E3 A0 A0
  • 41. JBehave – Advanced Meta information Meta Followed by name value properties separated by @ Example: Meta filtering Used for selecting of stories Meta @author Nikolay Vasilev @organization Bulgarian Java Users Group -author *Vasilev
  • 42. JBehave – Advanced Ant tasks and Maven plugin Integration with Spring, Pico, Guice Reporting options Console, Text, HTML, XML Default reports location in a Maven project: ${project.dir}/target/jbehave Example Test integration (JUnit and TestNG) See AnnotatedEmbedder example
  • 43. JBehave Reporting Options Reports HTML Report
  • 44. JBehave Reporting Options Failing Story HTML Report
  • 45. JBehave Reporting Options Pending Steps Story HTML Report
  • 46. JBehave Reporting Options Parametrized Story HTML Report
  • 47. JBehave – Eclipse Plugin Home Page Status: In development Non-trivial installation (next slides) Not very rich functionality but makes the life easier Provides Basic highlighting On match, the step in the story is linked to the mapped method Certain autocomplete when writing stories
  • 48. JBehave – Eclipse Plugin Example Keywords highlighting “ Jumping” from story to Steps class Autocomplete
  • 49. JBehave – Install Eclipse Plugin Download the plugin
  • 50. JBehave – Install Eclipse Plugin Eclipse > File > Import
  • 51. JBehave – Install Eclipse Plugin Existing Projects into Workspace
  • 52. JBehave – Install Eclipse Plugin Select archive file: > Browse
  • 53. JBehave – Install Eclipse Plugin Select archive file > Open
  • 54. JBehave – Install Eclipse Plugin Select archive file:
  • 55. JBehave – Install Eclipse Plugin Finish
  • 56. JBehave – Install Eclipse Plugin Project Editor > Select the new project
  • 57. JBehave – Install Eclipse Plugin File > Export
  • 58. JBehave – Install Eclipse Plugin Select > Deployable plug-ins and frag…
  • 59. JBehave – Install Eclipse Plugin Select > Deployable plug-ins and frag…
  • 60. JBehave – Install Eclipse Plugin Select the Plug-in & Chose Install into host
  • 61. JBehave – Install Eclipse Plugin Restart Eclipse (Chose ‘Yes’)
  • 62. JBehave – Install Eclipse Plugin The story files are with different icon 
  • 63. JBehave – Install Eclipse Plugin Not “recognized” stories > Select + Right Click > Open With > Behavior Editor
  • 64. JBehave – Install Eclipse Plugin Now the keywords are highlighted
  • 66. JBehave and Selenium Selenium A suite of tools to automate web app testing across many platforms. Abstracts away the interaction with the web layer (browser/server) Java, Perl, C#, C, etc. Selenium Object Tested WebApp Selenium RC Server Browsers
  • 67. JBehave and Selenium Selenium would let us focus on testing the web-app functionality Although, steps classes get cluttered by selenium calls Steps Selenium Object Tested WebApp Selenium RC Server Browsers Stories
  • 68. JBehave and Selenium JBehave and Selenium First thought - Steps will interact with the selenium object from the steps classes Steps Selenium Object Tested WebApp Selenium RC Server Browsers Stories
  • 69. JBehave and Selenium Page Objects Pattern Page object represent the services offered by a page Hides the knowledge of the page structure from the developer Steps Selenium Object Tested WebApp Selenium RC Server Browsers Stories Page Object
  • 70. JBehave and Selenium Rules of Thumb Keep assertions in the steps mapping classes Keep selenium interaction in the page objects Stories should address the functionality which the pages offer
  • 71. JBehave and Selenium What do we need to integrate JBehave and Selenium SeleniumConfiguration (part of JBehave Web) @BeforeScenario, @AfterScenario steps Responsible of start/stop selenium object Pages and Steps implementation Running selenium tests in an automated way (maven – integration-test phase) Tip: Configure Firefox for testing with Selenium
  • 72. Use Case – Web Testing Web app for our Use Case 2 JSPs – one for main form, another for result In order to run it are required: Run the web app on a web server Run the Selenium RC server with the selenium profile (see tip from prev. slide) Execute WebBmiCalculatorStories embedder as JUnit test
  • 73. Use Case – Web Testing Main form
  • 74. Use Case – Web Testing Result page
  • 75. Use Case – Web Testing The main form is also error page
  • 76. JBehave - Pros and Cons
  • 78. Use Case & Examples Code Use Case Code – Consists of 3 Maven 2 projects jug-bg-bdd-domain Domain Classes of the Application jug-bg-bdd-jbehave JBehave Examples (depending on the first project) jug-bg-bdd-web JBehave & Selenium Examples (depending on the first project)
  • 79. Use Case & Examples Code Source Code could be found on: http://code.google.com/p/bg-jug-resource-repository/
  • 80. References BDD Wiki Jbehave JBehave Tutorial Dan North – Introducing BDD Dan North - What’s in a Story? [pdf] BDD in Java and Groovy [pdf] TDD Beyond Junit BDD in a Nutshell
  • 81. References Ryan Greenhall – BDD by Example Localizing JBehave Scenarios Eric Evans - &quot;Domain-Driven Design: Tackling Complexity in the Heart of Software&quot;, Addison-Wesley JBehave Site :: Dependency Injection JBehave + Spring + Selenium Example
  • 82. References Selenium Project Page Objects Pattern Creating Firefox Profile for Selenium RC Tests JBehave Site :: Using Selenium BDD with JBehave Web 3, Selenium and Maven 2 for OS X Leopard Nice JBehave + Selenium + Maven Example Selenium Tutorial to set up a Selenium Grid
  • 83. Thank you for your attention!

Editor's Notes

  • #2: Bulgarian Java Users Group
  • #8: Use Case - description of steps or actions between a user (or &amp;quot;actor&amp;quot;) and a software system which leads the user towards something useful. User Story -  one or more sentences in the everyday or business language of the end user that captures what the user wants to achieve. Each user story is limited, so it fits on a small paper note card to ensure that it does not grow too large. A user story is an informal statement of the requirement as long as the correspondence of  acceptance testing procedures  is lacking. Bulgarian Java Users Group
  • #37: Bulgarian Java Users Group
  • #39: - ConfigurableEmbedder - allows the specification of the Configuration and CandidateSteps InjectableEmbedder -  allows the injection of a fully specified Embedder JUnitStory - provides a one-to-one mapping with the textual story JUnitStories - provides a many-to-one mapping with the textual story paths explicitly specified by overriding the  storyPaths()  method. Bulgarian Java Users Group
  • #44: Existing Projects into Workspace Bulgarian Java Users Group
  • #45: Existing Projects into Workspace Bulgarian Java Users Group
  • #46: Existing Projects into Workspace Bulgarian Java Users Group
  • #47: Existing Projects into Workspace Bulgarian Java Users Group
  • #49: Bulgarian Java Users Group
  • #51: Existing Projects into Workspace Bulgarian Java Users Group
  • #52: Bulgarian Java Users Group
  • #53: Bulgarian Java Users Group
  • #54: Bulgarian Java Users Group
  • #55: Bulgarian Java Users Group
  • #56: Bulgarian Java Users Group
  • #57: Bulgarian Java Users Group
  • #58: Bulgarian Java Users Group
  • #59: Bulgarian Java Users Group
  • #60: Bulgarian Java Users Group
  • #61: Bulgarian Java Users Group
  • #62: Bulgarian Java Users Group
  • #63: Bulgarian Java Users Group
  • #64: Bulgarian Java Users Group
  • #65: Bulgarian Java Users Group
  • #68: Bulgarian Java Users Group
  • #71: Bulgarian Java Users Group
  • #72: Bulgarian Java Users Group
  • #73: Bulgarian Java Users Group
  • #74: Bulgarian Java Users Group
  • #75: Bulgarian Java Users Group
  • #76: Bulgarian Java Users Group