SlideShare una empresa de Scribd logo
1 de 32
Introduction to Behavior Driven 
Development for Java Developers
            Gordon Force
          January 10, 2012
          January 10, 2012
What is Behavior Driven Development (BDD)?
 What is Behavior Driven Development (BDD)?

Short Definition
Short Definition
   “Behaviour‐driven development is about implementing an 
     application by describing its behaviour from the 
     perspective of its stakeholders” – Dan North

A Bit More Complete
A Bit More Complete
   "a second‐generation, outside–in, pull‐based, multiple‐
     stakeholder, multiple‐scale, high‐automation, agile 
                ,      p        , g                , g
     methodology. It describes a cycle of interactions with well‐
     defined outputs, resulting in the delivery of working, 
     tested software that matters.
     tested software that matters " – Dan North
                                        Dan North
Second Generation Built On …
   Second Generation Built On …
User Stories 
User Stories

eXtreme Programming (XP)
eXtreme Programming (XP)
  – Test Driven Development
  –AAcceptance Driven Test Planning
          t     Di     T t Pl   i
  – Continuous Integration (Automation)

Domain‐Driven Design
Outside‐In Methodology
Outside In Methodology
        Stories describe 
        Stories describe
       features from the 
       stakeholders POV


         Development 
            delivers 
        Runnable Tested 
        Runnable Tested
          Features aka 
         software that 
            matters
BDD Stories
BDD Stories
Multiple Stakeholder
                  Multiple‐Stakeholder
•   Multiple stakeholders (should) define an application’s behavior
•   Each stakeholder represents one or more business domains
     – Each domain uses a particular jargon or domain language


•   Stakeholders involvement  for OnPay Story Content
     –   Product: customer interactions, payments knowledge, SLAs
     –   Sales: sales programs (discounts), negotiating SLAs
         Sales: sales programs (discounts) negotiating SLAs
     –   Accounting: reconciliation, booking revenue, SOX & SAS‐70 compliance
     –   Security: authentication, encryption, web‐attacks, other PCI compliance items
     –   Data Center: app monitoring,  patching , system capacity,  other ITIL  funcs
         Data Center: app monitoring patching system capacity other ITIL funcs
     –   Legal: user agreements, fee language, SLA agreements
     –   Customer Support: call support performance, support tool effectiveness
     –   Web Design: website appearance (UI Widgets) and usability
         Web Design: website appearance (UI Widgets) and usability
User Stories Overview
         User Stories Overview
• Created a planning tool
  Created a planning tool
  – Must have a business value
  – Must be testable
    Must be testable 
  – Small enough to fit in a sprint / iteration
• E h i
  Emphasizes conversations over specifications
                       ti           ifi ti
• Narrative describes a feature
  – One or more stories can describe a feature
• Acceptance Criteria defines doneness
      p
The Team Writes the Story
       The Team Writes the Story
• SHs describe features & outcomes in the 1st draft
  SHs describe features & outcomes in the 1
• All work together to complete the story
   – Express interactions between domain objects as well
     Express interactions between domain objects as well 
     defined and verifiable behaviors
   – Blend terms from multiple domains to create a 
     ubiquitous language used by the team to write the 
     story.
   – Leverage expertise within the team
                            h h
      • QA identifies testable contexts, Dev estimates the scope, 
        Web Design maps user interaction onto UI elements
                 g      p
BDD Story Format
                             BDD Story Format
Title (one line describing the story)

Narrative:                              •   Described as a User Story
In order to [benefit]                   •   Uses a Ubiquitous Language (UL) developed by the team
As a [role]                             •   Benefit is the rationale, might be testable
I want to [feature]                     •   Should fit in an sprint, otherwise break up into smaller stories

Acceptance Criteria:
Scenario: Title                         •   Describes outcomes for an event.
Given [context]                         •   The event describes the feature
 And [some more context]...             •   Must be testable
When [event]                            •   Not always simple
Then [outcome]
      [         ]                       •                          gp
                                            Minimize domain mixing per scenario
 And [another outcome]...

Scenario: ...                           •   Describes another outcome for another event and context
P2P Send Money Story
                        P2P Send Money Story
Title (one line describing the story)   Send P2P Money

Narrative:                              Narrative:
In order to [benefit]                   In order to spend less time paying my debts in person or by mail
As a [role]                             As a Person
                                        I want to send money online to another Person
                                        I want to send money online to another Person
I want to [feature]

                                        Scenario: Payor has enough funds
Scenario: Title                         Given Bob is logged into his account page and has an available 
Given [context]                         balance of $100
                                                    $
 And [some more context]...             When filling out the send money form with $90.01 in the amount 
When [event]                            field, sue@localhost in the recipient field and clicking on the submit 
Then [outcome]                          button 
                                        Then OnPay updates the account page with an available balance of 
 And [another outcome]...
     [               ]                  $90 and a pending $10 transaction to sue@localhost
                                        $90 and a pending $10 transaction to sue@localhost
                                        And adds a payment notification to the account page for Sue in the 
                                        notifications section

Scenario: ...
Scenario:                               Scenario : Payor does not have enough funds
                                                     y                     g
Pull Based is better than Push Based
 Pull Based is better than Push Based
• Pushing is imposed features & deadlines
   us g s posed eatu es & dead es
   – What we need is you to develop this by last week
• Pulling is more efficient and enables scaling
        g                                     g
   – Stories are prioritized by business value.
      • Clarifies relative importance
   – The team commits to story delivery based on priority 
     and capacity
      • Creating sub‐stories when required
               g                    q
   – With a deep backlog more than one team can help
   – Pulling requires Outside In communication
The Pull Cycle
                The Pull Cycle
• SHs add BV prioritized stories to the backlog
  SHs add BV prioritized stories to the backlog. 
• Dev pulls the highest priority stories to work 
  on that fit in a sprint.
  on that fit in a sprint
• Dev demonstrates completed stories as 
  Runnable Tested Features (RTF) to SHs. 
  R     bl T        dF       (RTF) SH
  – RTF is software that matters.
• The business pulls a collection of RTFs to 
  release as an application or update.
High Automation: BDD Testing
High Automation: BDD Testing
The Red Green Refactor TDD Cycle
The Red‐Green‐Refactor TDD Cycle

                  1) Write a Test 
                    First (fails)


                            jUnit,
                            TestNG
    3) Refactor
                                     2) Code Until 
                                     2) Code Until
                                      Test Passes
BDD Testing is not Unit Testing
   BDD Testing is not Unit Testing
• jUnit was written for developers
  jUnit was written for developers
  – Does a great job for object / unit testing
  – Popularized “code by example” development
      p                 y       p            p
• Cumbersome to adapt for story testing
  – Test names are method names
    Test names are method names
  – Test runners assume one test per object lifetime
  – jUnit reports use asserts and their stack traces to 
    j       p
    describe failures
     • It takes a developer to understand what failed.
The BDD Cycle
              The BDD Cycle
                        1) Focus on one 
                         )
                            scenario

                    2) Write a failing step 
                         definition

                            3) Write failing 
                               example




              5) Refactor
                                                4) Get example 
                                                    to pass
                                                    t

7) Refactor
                                                       6) Step Up when 
                      jbehave,                         Example Passes
                                                       Example Passes
                      easyb
jbehave Overview
              jbehave Overview
• Automates story testing
  Automates story testing 
   – Parses stories written in text, ODT and Google Docs
   – Executes stories synchronously or asynchronously
     Executes stories synchronously or asynchronously
   – Enables Outside‐In development
• Integrates with existing test runners
  Integrates with existing test runners
   – jUnit, TestNG, Spring Test
   – Enables integrate with maven ant eclipse
     Enables integrate with maven, ant, eclipse
• Emits stakeholder readable reports
   – Supports custom templates
     Supports custom templates
Remote Web Testing Client
  Remote Web Testing Client
                            jbehave
      Test Runner
      Test Runner
                                 steps     stories
 jUnit / Spring / TestNG


embedder        story maps      selenium

   Test runner dependent
    configuration classes        firefox
Direct Testing Application
   Direct Testing Application
                            jbehave
      Test Runner
      Test Runner
                                   steps       stories
 jUnit / Spring / TestNG

                                application 
embedder        story maps
                                  code

   Test runner dependent
    configuration classes
jbehave Usage
               jbehave Usage
1. Write  a Story
1 Write a Story
2. Configure Embedder and Story Mapper
  – Li k t i
    Links stories, steps and reports together
                    t      d      t t th
3. Implement steps using the BDD Cycle
  – Annotations associate steps with methods
4. Run the story
5. View Generated Reports
Mapping Steps with Annotations
    Mapping Steps with Annotations
package com.forceassociates.onpay_webtester.steps;

import
i        org.jbehave.core.annotations.Given;
             j                   i     i
import   org.jbehave.core.annotations.Then;
import   org.jbehave.core.annotations.When;
import   org.junit.Assert;
         org junit Assert;

public class P2PSendMoneySteps {

    @Given("$payor is logged into his account page")
    public void loginToAccountPage(String payor) {
         // Add code under test or 
         // Selenium client action here to carry out the step
    }
}
Handling the Unexpected
      Handling the Unexpected
• P2P Send Money Story needs registered users
  P2P Send Money Story needs registered users
  – Need additional stories describing registration
• How to handle with in an Agile project
  How to handle with in an Agile project
  – Review options with your team
  – Focus on creating a story that matters
     • Create missing stories & implement to cover gap
     •M k i i
       Mock missing services & data
                           i   &d t
     • Last resort is returning the story to the backlog
Register People Story
                     g         p       y
Narrative:

In order to use OnPay
As a Person
I want to register for OnPay

Scenario: Person Registers for OnPay 

Given a browser is on the OnPay registration page
When filling out the registration form with <name> in the name field, <email> in the email 
    address field, <amount> in the initial funding field and clicking on the submit button  
Then OnPay creates an account for <name> and displays their account page

Examples:
|name |email |amount | 
|
|Bob|bob@localhost|$100|
     |    @        |$    |
|Sue |sue@localhost |$450|
Dependant Given Story for a Scenario
  Dependant Given Story for a Scenario
P2P Send Money

Narrative:

In order to spend less time paying my debts in person or by mail
As a Person
I want to send money online to another Person

Scenario: Payor has enough funds

GivenStories: com/forceassociates/onpay_webtester/stories/RegisterPeople.given.txt

Given Bob is logged into his account page and has an available balance of $100
       Bob is logged into his account page and has an available balance of $100
When filling out the send money form with $90.01 in the amount field, sue@localhost in the 
    recipient field and clicking on the submit button 
Then OnPay updates the account page with an available balance of $90 and a pending $10 
    transaction to sue@localhost
And adds a payment notification to the account page for Sue in the notifications section
Invoking jbehave
              Invoking jbehave
• Maven Plugin
  Maven Plugin
  – jbehave archetypes use integration‐test phase
     • mvn integration‐test
  – Very customizable 
• Eclipse
  – Execute as a jUnit test or using m2eclipse
• Example story report on the next two pages
       l                   h
Other Testing Thoughts
       Other Testing Thoughts
• Story tests are long lived
  Story tests are long lived
  – Should be used for regression tests
  – Subset for used for build acceptance tests
  – Must be kept up to date
• Testing Low Level Code
  – Interactions bet een objects are beha iors
    Interactions between objects are behaviors
  – Can be done with either jBehave or jUnit
Restart the BDD Cycle
         Restart the BDD Cycle
• Facilitate story development
  Facilitate story development
  – Provide a demo instance to SHs
  – Mock out features not implemented yet
    Mock out features not implemented yet
Bibliography
•   Kent Beck
     –   Extreme Programming Explained (2nd Edition), Addison‐Wesley Professional, 2004
     –   Test Driven Development: By Example, Addison‐Wesley Professional, 2002
     –   Web: http://www.threeriversinstitute.org/blog/


•   Mike Cohn
     –   Applied Users Stories: For Agile Software Development, Addison‐Wesley‐Professional, 2004
     –   Web: http://www.mountaingoatsoftware.com/topics/user‐stories


•   Eric Evans 
     –   Domain‐Driven Design: Tackling Complexity in the Heart of Software, Addison‐Wesley Professional, 2003
         D    i Di     D i T kli C           l i i h H           fS f        Addi    W l P f i         l 2003
     –   Web: http://domaindrivendesign.org/


•   Dan North
     –   The RSpec Book: Behaviour Driven Development with Rspec, Cucumber, and Friends, Pragmatic Bookshelf, 2010
         The RSpec Book: Behaviour Driven Development with Rspec Cucumber and Friends Pragmatic Bookshelf 2010
     –   Web: http://dannorth.net/ http://behaviour‐driven.org/BehaviourDrivenDevelopment
         http://www.slideshare.net/skillsmatter/bdd‐introduction
     –   jBehave: http://jbehave.org/
Presenter Information
         Presenter Information
Gordon Force Jr.
Gordon Force Jr
Principal at Force Associates
Email: gordon@force‐associates.com
Email gordon@force associates com
Twitter: @forceassociates
Example source code: https://github.com/gordon force
Example source code: https://github com/gordon‐force‐
  associates/onpay‐webtester

Más contenido relacionado

Similar a Introduction to BDD for Java with jBehave

Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1willmation
 
Behavior Driven Development - WPC 2011
Behavior Driven Development - WPC 2011Behavior Driven Development - WPC 2011
Behavior Driven Development - WPC 2011Fabio Armani
 
Behavior Driven Development - TdT@Cluj #15
Behavior Driven Development - TdT@Cluj #15Behavior Driven Development - TdT@Cluj #15
Behavior Driven Development - TdT@Cluj #15Tabăra de Testare
 
Bridging the gap between business and technology - Behaviour Driven Developme...
Bridging the gap between business and technology - Behaviour Driven Developme...Bridging the gap between business and technology - Behaviour Driven Developme...
Bridging the gap between business and technology - Behaviour Driven Developme...marcin_pajdzik
 
Agile Architecture in Odessa
Agile Architecture in OdessaAgile Architecture in Odessa
Agile Architecture in OdessaJohannes Brodwall
 
Tech talk specflow_bddx_hassa_nagy
Tech talk specflow_bddx_hassa_nagyTech talk specflow_bddx_hassa_nagy
Tech talk specflow_bddx_hassa_nagySkills Matter
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumberNibu Baby
 
"Тестирование в Agile в среде виртуализации Vagrant+Docker", Владимир Сидорен...
"Тестирование в Agile в среде виртуализации Vagrant+Docker", Владимир Сидорен..."Тестирование в Agile в среде виртуализации Vagrant+Docker", Владимир Сидорен...
"Тестирование в Agile в среде виртуализации Vagrant+Docker", Владимир Сидорен...DataArt
 
Expo qa from user stories to automated acceptance tests with bdd
Expo qa   from user stories to automated acceptance tests with bddExpo qa   from user stories to automated acceptance tests with bdd
Expo qa from user stories to automated acceptance tests with bddEduardo Riol
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumberDaniel Kummer
 
Behaviour Driven Development
Behaviour Driven DevelopmentBehaviour Driven Development
Behaviour Driven DevelopmentBen Goldin
 
Webinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
Webinar-From user stories to automated acceptance tests with BDD-Eduardo RiolWebinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
Webinar-From user stories to automated acceptance tests with BDD-Eduardo RiolatSistemas
 
Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Tudor Constantin
 
Inventing the future Business Programming Language
Inventing the future  Business Programming LanguageInventing the future  Business Programming Language
Inventing the future Business Programming LanguageESUG
 
Building In Quality: The Beauty Of Behavior Driven Development (BDD)
Building In Quality: The Beauty Of Behavior Driven Development (BDD)Building In Quality: The Beauty Of Behavior Driven Development (BDD)
Building In Quality: The Beauty Of Behavior Driven Development (BDD)Synerzip
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by ExampleNalin Goonawardana
 
Bare-Bones Software Architecture
Bare-Bones Software ArchitectureBare-Bones Software Architecture
Bare-Bones Software ArchitectureJohannes Brodwall
 
From Specification To Success
From Specification To SuccessFrom Specification To Success
From Specification To SuccessPatchSpace Ltd
 

Similar a Introduction to BDD for Java with jBehave (20)

Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1
 
Behavior Driven Development - WPC 2011
Behavior Driven Development - WPC 2011Behavior Driven Development - WPC 2011
Behavior Driven Development - WPC 2011
 
Behavior Driven Development - TdT@Cluj #15
Behavior Driven Development - TdT@Cluj #15Behavior Driven Development - TdT@Cluj #15
Behavior Driven Development - TdT@Cluj #15
 
Bridging the gap between business and technology - Behaviour Driven Developme...
Bridging the gap between business and technology - Behaviour Driven Developme...Bridging the gap between business and technology - Behaviour Driven Developme...
Bridging the gap between business and technology - Behaviour Driven Developme...
 
Agile Architecture in Odessa
Agile Architecture in OdessaAgile Architecture in Odessa
Agile Architecture in Odessa
 
Tech talk specflow_bddx_hassa_nagy
Tech talk specflow_bddx_hassa_nagyTech talk specflow_bddx_hassa_nagy
Tech talk specflow_bddx_hassa_nagy
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
"Тестирование в Agile в среде виртуализации Vagrant+Docker", Владимир Сидорен...
"Тестирование в Agile в среде виртуализации Vagrant+Docker", Владимир Сидорен..."Тестирование в Agile в среде виртуализации Vagrant+Docker", Владимир Сидорен...
"Тестирование в Agile в среде виртуализации Vagrant+Docker", Владимир Сидорен...
 
Scrum + bdd + ddd
Scrum + bdd + dddScrum + bdd + ddd
Scrum + bdd + ddd
 
Expo qa from user stories to automated acceptance tests with bdd
Expo qa   from user stories to automated acceptance tests with bddExpo qa   from user stories to automated acceptance tests with bdd
Expo qa from user stories to automated acceptance tests with bdd
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
Behaviour Driven Development
Behaviour Driven DevelopmentBehaviour Driven Development
Behaviour Driven Development
 
Webinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
Webinar-From user stories to automated acceptance tests with BDD-Eduardo RiolWebinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
Webinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
 
Agile Architecture
Agile ArchitectureAgile Architecture
Agile Architecture
 
Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)
 
Inventing the future Business Programming Language
Inventing the future  Business Programming LanguageInventing the future  Business Programming Language
Inventing the future Business Programming Language
 
Building In Quality: The Beauty Of Behavior Driven Development (BDD)
Building In Quality: The Beauty Of Behavior Driven Development (BDD)Building In Quality: The Beauty Of Behavior Driven Development (BDD)
Building In Quality: The Beauty Of Behavior Driven Development (BDD)
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
 
Bare-Bones Software Architecture
Bare-Bones Software ArchitectureBare-Bones Software Architecture
Bare-Bones Software Architecture
 
From Specification To Success
From Specification To SuccessFrom Specification To Success
From Specification To Success
 

Más de Marakana Inc.

Why Java Needs Hierarchical Data
Why Java Needs Hierarchical DataWhy Java Needs Hierarchical Data
Why Java Needs Hierarchical DataMarakana Inc.
 
Deep Dive Into Android Security
Deep Dive Into Android SecurityDeep Dive Into Android Security
Deep Dive Into Android SecurityMarakana Inc.
 
Pictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User GroupPictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User GroupMarakana Inc.
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesMarakana Inc.
 
2010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-62010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-6Marakana Inc.
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Marakana Inc.
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Marakana Inc.
 
What's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovationWhat's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovationMarakana Inc.
 
jQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda KatzjQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda KatzMarakana Inc.
 
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...Marakana Inc.
 
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldMarakana Inc.
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldMarakana Inc.
 
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas EneboLearn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas EneboMarakana Inc.
 
Replacing Java Incrementally
Replacing Java IncrementallyReplacing Java Incrementally
Replacing Java IncrementallyMarakana Inc.
 
Learn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache BuildrLearn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache BuildrMarakana Inc.
 
Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)Marakana Inc.
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBMarakana Inc.
 
A hands on overview of the semantic web
A hands on overview of the semantic webA hands on overview of the semantic web
A hands on overview of the semantic webMarakana Inc.
 

Más de Marakana Inc. (20)

JRuby at Square
JRuby at SquareJRuby at Square
JRuby at Square
 
Why Java Needs Hierarchical Data
Why Java Needs Hierarchical DataWhy Java Needs Hierarchical Data
Why Java Needs Hierarchical Data
 
Deep Dive Into Android Security
Deep Dive Into Android SecurityDeep Dive Into Android Security
Deep Dive Into Android Security
 
Securing Android
Securing AndroidSecuring Android
Securing Android
 
Pictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User GroupPictures from "Learn about RenderScript" meetup at SF Android User Group
Pictures from "Learn about RenderScript" meetup at SF Android User Group
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and Techniques
 
2010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-62010 07-18.wa.rails tdd-6
2010 07-18.wa.rails tdd-6
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
 
What's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovationWhat's this jQuery? Where it came from, and how it will drive innovation
What's this jQuery? Where it came from, and how it will drive innovation
 
jQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda KatzjQuery State of the Union - Yehuda Katz
jQuery State of the Union - Yehuda Katz
 
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
Pics from: "James Gosling on Apple, Apache, Google, Oracle and the Future of ...
 
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
 
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas EneboLearn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
Learn about JRuby Internals from one of the JRuby Lead Developers, Thomas Enebo
 
Replacing Java Incrementally
Replacing Java IncrementallyReplacing Java Incrementally
Replacing Java Incrementally
 
Learn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache BuildrLearn to Build like you Code with Apache Buildr
Learn to Build like you Code with Apache Buildr
 
Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDB
 
A hands on overview of the semantic web
A hands on overview of the semantic webA hands on overview of the semantic web
A hands on overview of the semantic web
 

Último

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Último (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Introduction to BDD for Java with jBehave

  • 1. Introduction to Behavior Driven  Development for Java Developers Gordon Force January 10, 2012 January 10, 2012
  • 2. What is Behavior Driven Development (BDD)? What is Behavior Driven Development (BDD)? Short Definition Short Definition “Behaviour‐driven development is about implementing an  application by describing its behaviour from the  perspective of its stakeholders” – Dan North A Bit More Complete A Bit More Complete "a second‐generation, outside–in, pull‐based, multiple‐ stakeholder, multiple‐scale, high‐automation, agile  , p , g , g methodology. It describes a cycle of interactions with well‐ defined outputs, resulting in the delivery of working,  tested software that matters. tested software that matters " – Dan North Dan North
  • 3. Second Generation Built On … Second Generation Built On … User Stories  User Stories eXtreme Programming (XP) eXtreme Programming (XP) – Test Driven Development –AAcceptance Driven Test Planning t Di T t Pl i – Continuous Integration (Automation) Domain‐Driven Design
  • 4. Outside‐In Methodology Outside In Methodology Stories describe  Stories describe features from the  stakeholders POV Development  delivers  Runnable Tested  Runnable Tested Features aka  software that  matters
  • 6. Multiple Stakeholder Multiple‐Stakeholder • Multiple stakeholders (should) define an application’s behavior • Each stakeholder represents one or more business domains – Each domain uses a particular jargon or domain language • Stakeholders involvement  for OnPay Story Content – Product: customer interactions, payments knowledge, SLAs – Sales: sales programs (discounts), negotiating SLAs Sales: sales programs (discounts) negotiating SLAs – Accounting: reconciliation, booking revenue, SOX & SAS‐70 compliance – Security: authentication, encryption, web‐attacks, other PCI compliance items – Data Center: app monitoring,  patching , system capacity,  other ITIL  funcs Data Center: app monitoring patching system capacity other ITIL funcs – Legal: user agreements, fee language, SLA agreements – Customer Support: call support performance, support tool effectiveness – Web Design: website appearance (UI Widgets) and usability Web Design: website appearance (UI Widgets) and usability
  • 7. User Stories Overview User Stories Overview • Created a planning tool Created a planning tool – Must have a business value – Must be testable Must be testable  – Small enough to fit in a sprint / iteration • E h i Emphasizes conversations over specifications ti ifi ti • Narrative describes a feature – One or more stories can describe a feature • Acceptance Criteria defines doneness p
  • 8. The Team Writes the Story The Team Writes the Story • SHs describe features & outcomes in the 1st draft SHs describe features & outcomes in the 1 • All work together to complete the story – Express interactions between domain objects as well Express interactions between domain objects as well  defined and verifiable behaviors – Blend terms from multiple domains to create a  ubiquitous language used by the team to write the  story. – Leverage expertise within the team h h • QA identifies testable contexts, Dev estimates the scope,  Web Design maps user interaction onto UI elements g p
  • 9. BDD Story Format BDD Story Format Title (one line describing the story) Narrative: • Described as a User Story In order to [benefit] • Uses a Ubiquitous Language (UL) developed by the team As a [role] • Benefit is the rationale, might be testable I want to [feature] • Should fit in an sprint, otherwise break up into smaller stories Acceptance Criteria: Scenario: Title • Describes outcomes for an event. Given [context] • The event describes the feature And [some more context]... • Must be testable When [event] • Not always simple Then [outcome] [ ] • gp Minimize domain mixing per scenario And [another outcome]... Scenario: ... • Describes another outcome for another event and context
  • 10. P2P Send Money Story P2P Send Money Story Title (one line describing the story) Send P2P Money Narrative: Narrative: In order to [benefit] In order to spend less time paying my debts in person or by mail As a [role] As a Person I want to send money online to another Person I want to send money online to another Person I want to [feature] Scenario: Payor has enough funds Scenario: Title Given Bob is logged into his account page and has an available  Given [context] balance of $100 $ And [some more context]... When filling out the send money form with $90.01 in the amount  When [event] field, sue@localhost in the recipient field and clicking on the submit  Then [outcome] button  Then OnPay updates the account page with an available balance of  And [another outcome]... [ ] $90 and a pending $10 transaction to sue@localhost $90 and a pending $10 transaction to sue@localhost And adds a payment notification to the account page for Sue in the  notifications section Scenario: ... Scenario: Scenario : Payor does not have enough funds y g
  • 11. Pull Based is better than Push Based Pull Based is better than Push Based • Pushing is imposed features & deadlines us g s posed eatu es & dead es – What we need is you to develop this by last week • Pulling is more efficient and enables scaling g g – Stories are prioritized by business value. • Clarifies relative importance – The team commits to story delivery based on priority  and capacity • Creating sub‐stories when required g q – With a deep backlog more than one team can help – Pulling requires Outside In communication
  • 12. The Pull Cycle The Pull Cycle • SHs add BV prioritized stories to the backlog SHs add BV prioritized stories to the backlog.  • Dev pulls the highest priority stories to work  on that fit in a sprint. on that fit in a sprint • Dev demonstrates completed stories as  Runnable Tested Features (RTF) to SHs.  R bl T dF (RTF) SH – RTF is software that matters. • The business pulls a collection of RTFs to  release as an application or update.
  • 14. The Red Green Refactor TDD Cycle The Red‐Green‐Refactor TDD Cycle 1) Write a Test  First (fails) jUnit, TestNG 3) Refactor 2) Code Until  2) Code Until Test Passes
  • 15. BDD Testing is not Unit Testing BDD Testing is not Unit Testing • jUnit was written for developers jUnit was written for developers – Does a great job for object / unit testing – Popularized “code by example” development p y p p • Cumbersome to adapt for story testing – Test names are method names Test names are method names – Test runners assume one test per object lifetime – jUnit reports use asserts and their stack traces to  j p describe failures • It takes a developer to understand what failed.
  • 16. The BDD Cycle The BDD Cycle 1) Focus on one  ) scenario 2) Write a failing step  definition 3) Write failing  example 5) Refactor 4) Get example  to pass t 7) Refactor 6) Step Up when  jbehave,  Example Passes Example Passes easyb
  • 17. jbehave Overview jbehave Overview • Automates story testing Automates story testing  – Parses stories written in text, ODT and Google Docs – Executes stories synchronously or asynchronously Executes stories synchronously or asynchronously – Enables Outside‐In development • Integrates with existing test runners Integrates with existing test runners – jUnit, TestNG, Spring Test – Enables integrate with maven ant eclipse Enables integrate with maven, ant, eclipse • Emits stakeholder readable reports – Supports custom templates Supports custom templates
  • 18. Remote Web Testing Client Remote Web Testing Client jbehave Test Runner Test Runner steps stories jUnit / Spring / TestNG embedder story maps selenium Test runner dependent configuration classes firefox
  • 19. Direct Testing Application Direct Testing Application jbehave Test Runner Test Runner steps stories jUnit / Spring / TestNG application  embedder story maps code Test runner dependent configuration classes
  • 20. jbehave Usage jbehave Usage 1. Write  a Story 1 Write a Story 2. Configure Embedder and Story Mapper – Li k t i Links stories, steps and reports together t d t t th 3. Implement steps using the BDD Cycle – Annotations associate steps with methods 4. Run the story 5. View Generated Reports
  • 21. Mapping Steps with Annotations Mapping Steps with Annotations package com.forceassociates.onpay_webtester.steps; import i org.jbehave.core.annotations.Given; j i i import org.jbehave.core.annotations.Then; import org.jbehave.core.annotations.When; import org.junit.Assert; org junit Assert; public class P2PSendMoneySteps { @Given("$payor is logged into his account page") public void loginToAccountPage(String payor) { // Add code under test or  // Selenium client action here to carry out the step } }
  • 22. Handling the Unexpected Handling the Unexpected • P2P Send Money Story needs registered users P2P Send Money Story needs registered users – Need additional stories describing registration • How to handle with in an Agile project How to handle with in an Agile project – Review options with your team – Focus on creating a story that matters • Create missing stories & implement to cover gap •M k i i Mock missing services & data i &d t • Last resort is returning the story to the backlog
  • 23. Register People Story g p y Narrative: In order to use OnPay As a Person I want to register for OnPay Scenario: Person Registers for OnPay  Given a browser is on the OnPay registration page When filling out the registration form with <name> in the name field, <email> in the email  address field, <amount> in the initial funding field and clicking on the submit button   Then OnPay creates an account for <name> and displays their account page Examples: |name |email |amount |  | |Bob|bob@localhost|$100| | @ |$ | |Sue |sue@localhost |$450|
  • 24. Dependant Given Story for a Scenario Dependant Given Story for a Scenario P2P Send Money Narrative: In order to spend less time paying my debts in person or by mail As a Person I want to send money online to another Person Scenario: Payor has enough funds GivenStories: com/forceassociates/onpay_webtester/stories/RegisterPeople.given.txt Given Bob is logged into his account page and has an available balance of $100 Bob is logged into his account page and has an available balance of $100 When filling out the send money form with $90.01 in the amount field, sue@localhost in the  recipient field and clicking on the submit button  Then OnPay updates the account page with an available balance of $90 and a pending $10  transaction to sue@localhost And adds a payment notification to the account page for Sue in the notifications section
  • 25. Invoking jbehave Invoking jbehave • Maven Plugin Maven Plugin – jbehave archetypes use integration‐test phase • mvn integration‐test – Very customizable  • Eclipse – Execute as a jUnit test or using m2eclipse • Example story report on the next two pages l h
  • 26.
  • 27.
  • 28.
  • 29. Other Testing Thoughts Other Testing Thoughts • Story tests are long lived Story tests are long lived – Should be used for regression tests – Subset for used for build acceptance tests – Must be kept up to date • Testing Low Level Code – Interactions bet een objects are beha iors Interactions between objects are behaviors – Can be done with either jBehave or jUnit
  • 30. Restart the BDD Cycle Restart the BDD Cycle • Facilitate story development Facilitate story development – Provide a demo instance to SHs – Mock out features not implemented yet Mock out features not implemented yet
  • 31. Bibliography • Kent Beck – Extreme Programming Explained (2nd Edition), Addison‐Wesley Professional, 2004 – Test Driven Development: By Example, Addison‐Wesley Professional, 2002 – Web: http://www.threeriversinstitute.org/blog/ • Mike Cohn – Applied Users Stories: For Agile Software Development, Addison‐Wesley‐Professional, 2004 – Web: http://www.mountaingoatsoftware.com/topics/user‐stories • Eric Evans  – Domain‐Driven Design: Tackling Complexity in the Heart of Software, Addison‐Wesley Professional, 2003 D i Di D i T kli C l i i h H fS f Addi W l P f i l 2003 – Web: http://domaindrivendesign.org/ • Dan North – The RSpec Book: Behaviour Driven Development with Rspec, Cucumber, and Friends, Pragmatic Bookshelf, 2010 The RSpec Book: Behaviour Driven Development with Rspec Cucumber and Friends Pragmatic Bookshelf 2010 – Web: http://dannorth.net/ http://behaviour‐driven.org/BehaviourDrivenDevelopment http://www.slideshare.net/skillsmatter/bdd‐introduction – jBehave: http://jbehave.org/
  • 32. Presenter Information Presenter Information Gordon Force Jr. Gordon Force Jr Principal at Force Associates Email: gordon@force‐associates.com Email gordon@force associates com Twitter: @forceassociates Example source code: https://github.com/gordon force Example source code: https://github com/gordon‐force‐ associates/onpay‐webtester