![Page 1: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/1.jpg)
Acceptance Test-driven Development (ATDD) with Cucumber-jvm (and friends)
!!!!!!!Christopher Bartling
![Page 2: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/2.jpg)
What is Acceptance Test-driven Development?
• Elisabeth Hendrickson
• A practice in which the whole team collaboratively discusses acceptance criteria, with examples, and then distills the criteria and examples into a set of concrete acceptance tests before development begins.
• Builds a shared understanding of what we’re building and when to consider it done.
![Page 3: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/3.jpg)
Acceptance test-driven development cadence
• Discuss the requirements and acceptance criteria for the feature, creating examples.
• Distill these examples into executable test format.
• Cucumber: Create features and scenarios.
• Develop the feature and hook up the acceptance tests.
• Cucumber: Create step definitions and page objects.
• Demo the feature and successful acceptance tests.
![Page 4: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/4.jpg)
The acceptance test-driven cadence
�4
Discuss requirements, create examples
Distill examples into
acceptance tests
Develop features, hook up tests
Demo features and acceptance tests
Test-driven development
![Page 5: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/5.jpg)
Specification by example
• Gojko Adzic
• “Living documentation”
• Documentation from executable specifications.
• Promotes collaboration.
• Efficient validation of features.
• Implement features more effectively and with higher quality.
![Page 6: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/6.jpg)
Benefits of automated acceptance testing
• Forces a thorough analysis of a feature.
• Build concrete agreement about the exact behavior the feature should exhibit.
• Living, executable and trustworthy documentation.
• Automation allows more manual, exploratory testing.
• Scalable regression testing.
![Page 7: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/7.jpg)
Cucumber
• Tool for running automated acceptance tests written in a behavior-driven development (BDD) style.
• Given - When - Then
• Allows the execution of feature documentation written in business-facing text.
![Page 8: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/8.jpg)
Cucumber-jvm
• Java implementation of Cucumber.
• Supports popular JVM programming languages.
• Java, Groovy, Clojure, Scala, JRuby.
• Integrates with popular dependency injection containers.
• Spring Framework, Guice, PicoContainer.
• Support several runners: command-line, JUnit, Android.
![Page 9: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/9.jpg)
Groovy
• Dynamic language for the Java Virtual Machine.
• Supports Domain-Specific Languages (DSLs) and other compact syntax so your code becomes easy to read and maintain.
• Seamlessly integrates with existing Java classes, libraries, and frameworks.
• Compiles directly to standard JVM bytecode.
![Page 10: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/10.jpg)
Selenium WebDriver
• Automated browsing. Capabilities include:
• Navigating to web pages
• Handling user input
• Finding and interrogating the DOM
• JavaScript execution
• org.openqa.selenium.WebDriver is the the key Java interface against which tests should be written.
![Page 11: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/11.jpg)
Geb
• Browser automation abstraction over WebDriver.
• Provides an elegant jQuery-like content selection engine.
• Built with Groovy, providing an easy to use DSL.
• Useful for scripting, scraping and general automation of web browsers.
• Integrates nicely with Cucumber-jvm.
![Page 12: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/12.jpg)
Chromedriver
• Standalone server which implements WebDriver's wire protocol for Chromium.
• Consists of three separate pieces:
• The browser itself (“chrome")
• Language bindings provided by the Selenium project ("the driver”)
• Bridge server between "chrome" and the “driver" (the chromedriver binary, referred to as the “server").
• Developed by members of the Chromium and WebDriver teams.
![Page 13: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/13.jpg)
Gradle
• Build automation tool.
• Combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build.
• Provides a declarative way to describe all kinds of builds through sensible defaults.
• Powered by a Groovy DSL.
![Page 14: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/14.jpg)
Cucumber features
• Plain-text functional scenarios.
• Simple Given/When/Then syntax (Gherkin).
• Feature files are typically written before anything else and verified by business analysts, domain experts, etc. non technical stakeholders.
• Production code is then written outside-in, until the stor(ies) successfully pass.
![Page 15: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/15.jpg)
Cucumber feature example
Feature: Navigate through the NCAA basketball tournament site Background: Given I navigate to the website Scenario: Navigate to the first round of the tournament When I click the "First round" navigation pill link Then I should see the first round brackets Scenario: Navigate to the second round of the tournament When I click the "Second round" navigation pill link Then I should see the second round brackets
![Page 16: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/16.jpg)
Cucumber step definitions
• The feature file “code-behind”.
• The executable part of Cucumber.
• Uses regular expressions to bind to feature file phrase.
When(~'^I click the "([^"]*)" navigation pill link$') { String navPillText -> page.$('a', text: navPillText).click() }
![Page 17: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/17.jpg)
Cucumber Support
• Cucumber provides a number of hooks which allow us to run blocks at various points in the Cucumber test cycle.
• Place hook implementations in file under the support directory.
• Use tagged hooks if you want more fine grained control.
• All defined hooks are run whenever the relevant event occurs.
![Page 18: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/18.jpg)
Page object pattern
• Allows modeling web content in a reusable and maintainable way.
• Reduces the amount of duplicated code.
• If the UI changes, the fix need only be applied in one place.
• Geb provides support for the Page Objects pattern through the geb.Page and geb.Module abstractions.
�18
![Page 19: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/19.jpg)
Demonstrations
![Page 20: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/20.jpg)
Reflection
• When you plan features, are you enumerating acceptance criteria and coming to shared understanding of Done?
• Are you converting those acceptance criteria into executable examples in an automated testing framework?
• What is preventing you from using acceptance test-driven development?
�20
![Page 21: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/21.jpg)
GitHub repository
• https://github.com/cebartling/ncaa-basketball-tournament
• web-client: Backbone.js-based application
• acceptance-tests: Cucumber-jvm project, Gradle-based build
![Page 22: Acceptance Test-driven Development with Cucumber-jvm](https://reader034.vdocuments.us/reader034/viewer/2022052307/5551280bb4c905b3598b4887/html5/thumbnails/22.jpg)
Resources
• http://testobsessed.com/2008/12/acceptance-test-driven-development-atdd-an-overview/
• http://testobsessed.com/wp-content/uploads/2011/04/atddexample.pdf
• http://specificationbyexample.com/
�22