Cucumber Crash Course
Upcoming SlideShare
Loading in...5
×
 

Cucumber Crash Course

on

  • 1,740 views

This presentation was the kick-off for the brown-bag series of learning sessions that AgilityFeat.com is hosting for their software development teams.

This presentation was the kick-off for the brown-bag series of learning sessions that AgilityFeat.com is hosting for their software development teams.

Statistics

Views

Total Views
1,740
Views on SlideShare
1,740
Embed Views
0

Actions

Likes
3
Downloads
33
Comments
2

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

12 of 2

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Thanks for joining meToday we are going to step through a crash course on Cucumber & GherkinWe will:Start with the benefitsProvide a brief primer on the mechanicsProvide an end-to-end exampleAnd cover the different approaches to gherkin feature writingSound good?OK – let’s get started
  • Why do Acceptance Test Driven Development?Well, [step through pic]It also helps the team work with confidence
  • #1 – in this case, English#2A common language between the business and the tech teamHelping you understand better what needs to be builtAnd, helps the business better understand what you are building#3 Cucumber is a communication tool more than anything – automation is just a secondary benefit#4 Examples are powerful stuffThey have the power to turn high-level acceptance criteria into specific & actionable acceptance tests (either to be carried out manually, or, with automation)They also engage our brains enabling us to visualize scenarios & figure out edge cases we may otherwise miss#5 This is all buttressed by the idea of describing the behavior of an application you are hoping to verify
  • So, really, it’s not just about automation, it’s about communication. To bring this point home, here’s a quote from the creator of Cucumber
  • Okay, let’s change gears and step through the mechanics of CucumberCucumber uses Gherkin which is a universalTo be clear -- Gherkin can be used in other BDD frameworks that use other programming languagesFor our purposes, we’ll be using Cucumber & RubySo, in Cucumber, there is a default folder structure – let’s step through it
  • Capybara API: https://gist.github.com/428105
  • Basic example (from end-to-end earlier)
  • Extend it – there are two additional keywordsBut may be indicative of the need for another scenarioBut your mileage may varyDepends on the readability and if it works for you and the team
  • The words don’t matter to Cucumber. They should matter to YOU
  • This seems much more readable – don’t you think?
  • Helper text – aka User Stories can go here
  • Freedom to specify data in different ways – e.g. headings down the site, or just specify a listThe pipes’ spacing doesn’t matter to Cucumber

Cucumber Crash Course Cucumber Crash Course Presentation Transcript

  • presents RELEASE THE GHERKIN!©2012 AgilityFeat Inc
  • © 2012 AgilityFeat, Inc.
  • What it is• Straight-forward language• Common Language• Communication Tool• Concrete Examples• Describes behavior © 2012 AgilityFeat, Inc.
  • #protip“make readability your main goal.Otherwise, a reader can easily feel morelike they’re a reading computer programthan a specification document”- Aslak Hellesøy (creator of Cucumber) © 2012 AgilityFeat, Inc.
  • Cucumber’s Natural Habitat © 2012 AgilityFeat, Inc.
  • Features Plain text Filename ends in .feature Describes behavior of system Lives in features directoryStep Ruby codeDefinitions Filename ends in.rb Does regex match of text from feature files Lives in features/step_definition directoryRuby Magic Your preferred gems go here Referenced in features/support/env.rbApplication We will be testing a web-pageUnder Test © 2012 AgilityFeat, Inc.
  • ExampleFeature: Brown Bag DemoScenario: Google Search Given I am on “http://www.google.com” When I search for “Hello World” Then I should see results containing the search phrase © 2012 AgilityFeat, Inc.
  • SolutionGiven /^I am on “(*^”+*)”$/ do |arg1| visit(arg1)endWhen /^I search for “(*^”+*)”$/ do |arg1| @search_phrase = arg1 within(:css, “#gbqfqw”) do fill_in ‘q’, :with => @search_phrase endendThen /^I should see results containing the search phrase$/ do page.should have_content(@search_phrase)end © 2012 AgilityFeat, Inc.
  • Feature: Class DemonstrationScenario: Show a Hello World Given I want to say “Hello World!” When I execute the application Then I should see the message © 2012 AgilityFeat, Inc.
  • Feature: Class DemonstrationScenario: Show a Hello World Given I want to say “Hello World!” When I execute the application Then I should see the message And it should be italic But it should not be bold © 2012 AgilityFeat, Inc.
  • Feature: Class DemonstrationScenario: Show a Hello World * I want to say “Hello World!” * I execute the application * I should see the message * it should be italic * it should not be bold © 2012 AgilityFeat, Inc.
  • Feature: Class DemonstrationScenario: Show a Hello World Given I want to say “Hello World!” When I execute the application Then I should see the message And it should be italic But it should not be bold © 2012 AgilityFeat, Inc.
  • Feature: Class DemonstrationIn order to expose you to new ideasAs an instructorI want to show you an end-to-end exampleScenario: Show a Hello World Given I want to say “Hello World!” When I execute the application Then I should see the message And it should be italic But it should not be bold © 2012 AgilityFeat, Inc.
  • Feature: Class DemonstrationAs an instructorI would like to show an end-to-end exampleSo that I can expose you to new ideasBackground: Given I want to say “Hello World!” When I execute the application Then I should see the messageScenario: Show an italicized Hello World And it should be italicScenario: Show a bold Hello World But it should not be2012 AgilityFeat, Inc. © bold
  • Feature: International DisplayScenario: Display Hello World in English Given I want to say “Hello World!” When I execute the application And I specify English as the language Then the output should be “Hello World!”Scenario: Display Hello World in Spanish Given I want to say “Hello World!” When I execute the application And I specify Spanish as the language Then the output should be “¡Hola, mundo!”Scenario: Display Hello World in German Given I want to say “Hello World!” When I execute the application And I specify German as the language Then the output should © 2012 AgilityFeat, Inc. be “Hallo Welt!”
  • Feature: Internationalize Hello WorldScenario Outline: Display in multiple languages Given I want to say “Hello World!” When I execute the application And I specify “<language>” as the language Then the output should be “<output>”Examples: | language | output | | English | Hello World! | | Spanish | ¡Hola, mundo! | | German | Hallo Welt! | © 2012 AgilityFeat, Inc.
  • Feature: Travel The WorldScenario: Keep Track Of Visits Given a list like this: | Location | Times visited | | Costa Rica | 0 | | Germany | 0 | When I travel to Costa Rica Then the list should look like this: | Location | Times visited | | Costa Rica | 1 | | Germany | 0 | © 2012 AgilityFeat, Inc.
  • Doc stringsScenario: Look up hostel reservation e-mailWhen I search for “Alexander House”Then I should see the following message:"""Welcome Mr. Haeffner.You’ll be staying in the bunk house this visit.Please refrain from stealing our towels (again).""” © 2012 AgilityFeat, Inc.
  • Recap -- Features• Plain text files that end in .feature• They live in the root of the features directory• Given, When, Then, And, But are trigger words• They matter most for readability• Descriptive text can go at the top• There are several approaches to abstract features and make them more readable• Usage depends on intent & team understanding © 2012 AgilityFeat, Inc.
  • Recap -- Step Definitions• Ruby files that live in features/step_definitions• Matches plain text from feature files• Stores it into a variable• You can set this to a class level variable for use across your test scenario• Use a gem to get where you need to go (e.g. Capybara for web testing) © 2012 AgilityFeat, Inc.
  • Recap -- System Setup• Gems you want to use can be added to env.rb• It lives in the features/support directory• If/when you create helper methods, create a ruby file and place them in this directory• If you add something to your test harness and execution order is important, place it in env.rb – it loads before everything else © 2012 AgilityFeat, Inc.