Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Cucumber, cuke4duke, and Groovy




          Christopher Bartling
Summary

• Acceptance Test-driven Development
• Introduce Cucumber concepts
• Introduce cuke4duke’s role
• Introduce Groov...
Presentation materials


• https://bitbucket.org/cebartling/
  presentations/
• Presentation and demo in repository
Why?

• Customer/business not engaged in story
  process
• User stories without good acceptance tests
• Ambiguous “develop...
Acceptance Test-Driven
    Development
• Acceptance tests are owned by the
  customer/business owner
• Specify the “what” ...
Why ATDD?

• Features need to be unambiguously and
  concisely specified
• Developers need to know when they are
  done wit...
Cucumber
• A behavior-driven development (BDD) tool
• Outside-in testing
• Business-readable DSL
• Implemented in Ruby, ru...
Cucumber

• Features and scenarios
• Steps
• Step definitions
• Hooks
• Tags
Features

• Features are modules of functionality
• Feature files have a .feature extension
• Written in Gherkin
• Contain ...
Feature example

Feature: Serve coffee
In order to earn money
Customers should be able to
buy coffee at all times
Organizing Features
• The features directory can contain
  subdirectories of feature themes

  features

        insurance...
Scenarios

• Consist of steps
 • Given, When, and Then
• Executable via matching step definitions
• http://blog.objectmento...
Steps

• Given: put the system in a known state
• When: describes the key action
• Then: observe outcome(s)
• Use And and ...
Step definitions
• Executable code
• Use regular expressions to match the steps
  in feature files
• Typically written in Ru...
Hooks

• Allows running code at various points of
  the Cucumber test cycle
• Typically reside in the support directory
• ...
Background

• Add context to a set of scenarios in a
  feature
• Run before each scenario, but after the
  Before hooks
• ...
Tags
• Allow categorization of features and
  scenarios
• Features and scenarios can have multiple tags
  @dbunit-load
  S...
Tagged hooks

• Allows fine-grained control of hooks for
  certain features or scenarios


  Before(‘@dbunit-load’)
cuke4duke

• Brings Cucumber to the JVM via JRuby
 • No need to program in Ruby
• Step definitions, hooks and other
  suppo...
JRuby dependency
• Use the following system property to install
  Ruby gems for use by cuke4duke

  -Dcucumber.installGems...
cuke4duke

• Ant support
• Maven support via plugin
• Spring Framework support (Java step
  definitions only)
• Google Guic...
Filtering with tags
• Tags are helpful for filtering groups of
  scenarios during a execution run
• Ensure Maven POM has cu...
Groovy’s role

• Step definitions can be written in many JVM
  languages
• Groovy works well for step definitions and
  othe...
cuke4duke.GroovyDsl


• Given, When, Then DSL for your Groovy
  step definitions
• No need to use Java annotations
WebDriver
• Web UI testing tool
• Being merged with Selenium for 2.0 release
• Native browser control, not JavaScript
 • F...
PageObjects pattern

• Use the PageObject pattern to verify web
  elements on a page
 • DRY up your verification logic
• Us...
Cucumber book


•   Co-authored by Aslak Hellesøy

    •   Creator of Cucumber and
        cuke4duke
Interesting reads

• http://blog.dannorth.net/whats-in-a-story/
• http://www.martinfowler.com/bliki/
  BusinessReadableDSL...
Contact information

• chris.bartling@gmail.com
• Twitter: cbartling
• Blog: http://bartling.blogspot.com
Upcoming SlideShare
Loading in …5
×

Cucumber, Cuke4Duke, and Groovy

8,116 views

Published on

Presentation that I gave to the Groovy Users of Minnesota group on May 11, 2010. Using Cucumber, cuke4duke, and Groovy together for acceptance test-driven development.

  • Be the first to comment

Cucumber, Cuke4Duke, and Groovy

  1. 1. Cucumber, cuke4duke, and Groovy Christopher Bartling
  2. 2. Summary • Acceptance Test-driven Development • Introduce Cucumber concepts • Introduce cuke4duke’s role • Introduce Groovy’s role • Demonstration and discussion
  3. 3. Presentation materials • https://bitbucket.org/cebartling/ presentations/ • Presentation and demo in repository
  4. 4. Why? • Customer/business not engaged in story process • User stories without good acceptance tests • Ambiguous “developer done”
  5. 5. Acceptance Test-Driven Development • Acceptance tests are owned by the customer/business owner • Specify the “what” of a feature • Expressed in the language of the problem domain • Written as a team
  6. 6. Why ATDD? • Features need to be unambiguously and concisely specified • Developers need to know when they are done with a feature • Automated testing to ensure features never regress/break
  7. 7. Cucumber • A behavior-driven development (BDD) tool • Outside-in testing • Business-readable DSL • Implemented in Ruby, runs on JRuby • Supports tests in tables, ala FIT • http://cukes.info/
  8. 8. Cucumber • Features and scenarios • Steps • Step definitions • Hooks • Tags
  9. 9. Features • Features are modules of functionality • Feature files have a .feature extension • Written in Gherkin • Contain one or more scenarios
  10. 10. Feature example Feature: Serve coffee In order to earn money Customers should be able to buy coffee at all times
  11. 11. Organizing Features • The features directory can contain subdirectories of feature themes features insurance accounts_payable invoicing
  12. 12. Scenarios • Consist of steps • Given, When, and Then • Executable via matching step definitions • http://blog.objectmentor.com/articles/ 2008/11/27/the-truth-about-bdd
  13. 13. Steps • Given: put the system in a known state • When: describes the key action • Then: observe outcome(s) • Use And and But to augment the three steps
  14. 14. Step definitions • Executable code • Use regular expressions to match the steps in feature files • Typically written in Ruby • Foreshadow: cuke4duke allows any JVM language to be used
  15. 15. Hooks • Allows running code at various points of the Cucumber test cycle • Typically reside in the support directory • Scenario hooks: Before, After • Step hooks: AfterStep
  16. 16. Background • Add context to a set of scenarios in a feature • Run before each scenario, but after the Before hooks • Typically consist of Given and And steps
  17. 17. Tags • Allow categorization of features and scenarios • Features and scenarios can have multiple tags @dbunit-load Scenario: Delete a photo album
  18. 18. Tagged hooks • Allows fine-grained control of hooks for certain features or scenarios Before(‘@dbunit-load’)
  19. 19. cuke4duke • Brings Cucumber to the JVM via JRuby • No need to program in Ruby • Step definitions, hooks and other supporting classes can be implemented in a variety of JVM languages
  20. 20. JRuby dependency • Use the following system property to install Ruby gems for use by cuke4duke -Dcucumber.installGems=true • Necessary for first-time installs and cuke4duke upgrades
  21. 21. cuke4duke • Ant support • Maven support via plugin • Spring Framework support (Java step definitions only) • Google Guice support
  22. 22. Filtering with tags • Tags are helpful for filtering groups of scenarios during a execution run • Ensure Maven POM has cukeArgs as a pass- through argument <cucumberArg>${cukeArgs}</cucumberArg> • Use the work in progress tag: @wip mvn cuke4duke:cucumber -DcukeArgs="--tags @wip"
  23. 23. Groovy’s role • Step definitions can be written in many JVM languages • Groovy works well for step definitions and other helper objects
  24. 24. cuke4duke.GroovyDsl • Given, When, Then DSL for your Groovy step definitions • No need to use Java annotations
  25. 25. WebDriver • Web UI testing tool • Being merged with Selenium for 2.0 release • Native browser control, not JavaScript • Firefox extension • Internet Explorer Automation controls • Object-based API
  26. 26. PageObjects pattern • Use the PageObject pattern to verify web elements on a page • DRY up your verification logic • Use PageFactory to bind the WebDriver and WebElement objects to your PageObject implementation
  27. 27. Cucumber book • Co-authored by Aslak Hellesøy • Creator of Cucumber and cuke4duke
  28. 28. Interesting reads • http://blog.dannorth.net/whats-in-a-story/ • http://www.martinfowler.com/bliki/ BusinessReadableDSL.html • http://en.wikipedia.org/wiki/ Behavior_driven_development
  29. 29. Contact information • chris.bartling@gmail.com • Twitter: cbartling • Blog: http://bartling.blogspot.com

×