Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Behaviour-Driven Development with Calabash

Behaviour-Driven Development with Calabash

Behaviour-Driven Development has become the standard development process for crafting software on the web. In recent years tools such as Cucumber and Bahat have elevated automated acceptance testing into the toolchain of any discerning software engineer. But what about the thriving world of mobile development? Is it possible to practice outside-in test driven development when creating iOS, Android or hybrid applications? This session will examine the relatively new and emerging world of Behaviour-Driven Development for mobile applications.

Using an automated acceptance test framework called Calabash, we will examine how to build applications that are continuously tested against product requirements written in the Gherkin domain-specific language. Using the outside-in development method, a basic mobile application will be constructed during the session, precisely meeting the product owners requirements.

Sam de Freyssinet

June 28, 2014
Tweet

More Decks by Sam de Freyssinet

Other Decks in Technology

Transcript

  1. Calabash B E H A V I O U R

    D R I V E N D E V E L O P M E N T with
  2. mobile The best childcare now starts on your mobile phone

    AVA I L A B L E T O D O W N L O A D O N
  3. – the way in which a person behaves in response

    to a particular situation or stimulus. behaviour – the way in which a machine works or functions. noun
  4. – Robert C. Martin (Uncle Bob) “ Cucumber is not

    a tool for testing applications. Cucumber is a philosophy for communicating requirements. ”
  5. Project System Features Scenarios Steps Step definitions Support code Automation

    library Business facing Technology facing Features defined by scenarios Specification by example in steps Written in natural language Step definition execution Assertion of specification Written in code
  6. Project System Features Scenarios Steps Step definitions Support code Automation

    library Business and technology boundary Steps are defined in natural language Step definitions are accepted by executing code Living system documentation
  7. – Lisa Crispin “ Cucumber is designed to help build

    bridges between the technical and nontechnical members of a software team. ”
  8. Feature A feature provides the overall context of intent, and

    is composed of one or more scenarios. Feature Scenario Scenario Outline Step Example
  9. Feature: Awesome feature In order to achieve a goal As

    an actor I want to be able to do the thing that achieves the goal
  10. Scenario Features are specified by scenarios, or use cases. Each

    scenario has a title. Scenarios contain steps that define the expected behaviour. Feature Scenario Scenario Outline Step Example
  11. Step Steps define the expected behaviour. Steps have use a

    minimal set of operating key words. Given, When, Then… And, But Feature Scenario Scenario Outline Step Example
  12. Scenario: Awesome scenario Given an initial state When I perform

    some action Then I should expect this behaviour
  13. Your Application Acceptance tests Test the expected behaviour of the

    application Step definitions Specify how each step of the acceptance test operates within the application Implement application logic Implement the code to make the scenario pass
  14. – Matt Wynne and Aslak Hellesøy, The Cucumber Book “

    Unit tests ensure you build the thing right. Acceptance tests ensure you build the right thing.”
  15. Calabash introducing C U C U M B E R

    M O B I L E A U T O M AT I O N L I B R A R Y
  16. Calabash iOS iOS 5, 6, 7 Ruby 2.x github.com/calabash/calabash-ios Calabash

    Android Android 4.0, 4.0.3, 4.1 Ruby 2.x github.com/calabash/calabash-android
  17. Touching Buttons Labels Input fields Table view cells Switches Map

    locations Window coordinates Text entry Input fields Text entry by table Clear input field Swipes & scrolling Swipe and scroll up, down, left, right Swipe on table view cell Swipe and scroll on label Pinches & zooms Swipe up, down, left, right Swipe on table view cell Swipe on label Scroll up, down, left, right Scroll on label P O I U Y T R E W Q L K J H G F D S A M N B V C X Z space return 12 3 github.com/calabash/calabash-ios/wiki/02-Predefined-steps
  18. C A L A B A S H I O

    S I N S T A L L A T I O N $ sudo gem install calabash-cucumber
  19. C A L A B A S H I O

    S P R O J E C T S E T U P $ calabash-ios setup ---------- Info ---------- Found several targets. Please enter name of target to duplicate. Default target: MyFirstProject. Just hit <Enter> to select default. MyFirstProject MyFirstProject Tests
  20. F E A T U R E S S E

    T U P $ calabash-ios gen ----------Question---------- I'm about to create a subdirectory called features. features will contain all your calabash tests. Please hit return to confirm that's what you want. ---------------------------
  21. C A L A B A S H C O

    M M A N D L I N E H E L P $ calabash-ios -h Usage: <command> can be one of $ calabash-ios help Man pages
  22. R E A D E V A L U A

    T E P R I N T L O O P $ calabash-ios console Running irb... irb(main):001:0> launcher.relaunch nil irb(main):002:0> github.com/calabash/calabash-ios/wiki/03.5-Calabash-iOS-Ruby-API
  23. Feature: Pow! Pow! Me Welcome Screen In order to understand

    the product quickly As a Pow! Pow! Me new customer I want to be able to use the app immediately from launch
  24. Scenario: Launch app first When I launch the application Then

    I should see “Pow! Pow! Me” And I should vacation opportunities
  25. Scenario: Launch app first When I launch the application Then

    I should see “Pow! Pow! Me” And I should vacation opportunities And I should be able to search for a Pow! Pow! vacation And I should be able to access my account information And I should be able to get help And I should see map search results
  26. Feature: Tune My Pow! Pow! In order to get the

    exact holiday I want As a Pow! Pow! Me customer I want to be able to set search parameters before searching
  27. Scenario: Tune My Pow! Pow! Given I am on the

    "Tune My Pow! Pow!" screen When I touch the “Pow! Pow! Me” button Then I should see a “Tune My Pow! Pow!”
  28. Scenario: Perform tuned search Given I am on the "Tune

    My Pow! Pow!" screen When I touch the "average price range" button And I touch the "five or more hours travel time" button And I touch the "long weekend on the mountain" button And I touch the "Lets Go!" button Then I should see "Shredding Pow! Pow!"
  29. Feature: Search Results In order to see potential Pow! Pow!

    trips As a Pow! Pow! searching customer I want to be able to view detailed matched search results
  30. Scenario: Search for average priced long weekend When I search

    for a far away, average priced, long weekend on the mountain Then I should see 3 search results And I should see a "Surprise me!" button
  31. Scenario: Surprise me! When I am on the search results

    page And I touch the "Surprise me!" button Then a random trip should be selected And I should see the trip details Scenario: Trip details Given there are 3 matching trips When I am on the search results page And I touch list item number 1 Then I should see the trip details
  32. User Experience describe the N O T T H E

    I M P L E M E N TAT I O N
  33. Scenario: Perform tuned search Given I am in need of

    a Pow! Pow! vacation When I want to find an average priced vacation And I am willing to travel for five or more hours And I want to spend a long weekend on the mountain Then I should see vacations that match my preferences
  34. Feature: Sign in with Facebook In order to authenticate register

    with existing information As a Pow! Pow! customer I want to be able to connect to my Facebook account
  35. B A C K D O O R A C

    C E S S C O D E @implementation AppDelegate - (NSString *)authenticateWithAccessToken:(NSString *)token { // Authenticate user with access token return [NSString stringWithFormat:@"Executed authenticateWithAccessToken: with %@", token]; } @end
  36. B A C K D O O R I M

    P L E M E N T A T I O N CALABASH=1
  37. B A C K D O O R C O

    N D I T I O N A L C O D E @implementation AppDelegate #ifdef CALABASH - (NSString *)authenticateWithAccessToken:(NSString *)token { // Authenticate user with access token return [NSString stringWithFormat:@"Executed authenticateWithAccessToken: with %@", token]; } #endif @end
  38. C A L A B A S H A P

    I – B A C K D O O R backdoor("authenticateWithAccessToken:", "abc123") => “Executed authenticateWithAccessToken: with abc123”
  39. Thank you! License Contact information Behaviour-Driven Development by Sam de

    Freyssinet is licensed under a Creative Commons Attribution 4.0 International License. Based on a work at def.reyssi.net. www.sittercity.com Sittercity is hiring! @samsoir @SittercityTech Behaviour-Driven Development with Calabash Written by Sam de Freyssinet Published in 2014 Additional material quoted from The Cucumber Book by Matt Wynne and Aslak Hellesøy