Cucumber, Cuke4Duke, and Groovy


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.

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 • 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 •
  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 • 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 • • BusinessReadableDSL.html • Behavior_driven_development
  29. 29. Contact information • • Twitter: cbartling • Blog:
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.