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.
4. Why?
• Customer/business not engaged in story
process
• User stories without good acceptance tests
• Ambiguous “developer done”
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. 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. 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/
11. Organizing Features
• The features directory can contain
subdirectories of feature themes
features
insurance
accounts_payable
invoicing
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. 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. 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. 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. 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. Tags
• Allow categorization of features and
scenarios
• Features and scenarios can have multiple tags
@dbunit-load
Scenario: Delete a photo album
18. Tagged hooks
• Allows fine-grained control of hooks for
certain features or scenarios
Before(‘@dbunit-load’)
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. 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. cuke4duke
• Ant support
• Maven support via plugin
• Spring Framework support (Java step
definitions only)
• Google Guice support
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. Groovy’s role
• Step definitions can be written in many JVM
languages
• Groovy works well for step definitions and
other helper objects
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. 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. Cucumber book
• Co-authored by Aslak Hellesøy
• Creator of Cucumber and
cuke4duke