0
Behaviour-drivendevelopment with   Cucumber        Kerry Buckley  BT DevCon6, 4 February 2013       http://www.flickr.com/p...
A developer tool forend-to-end testing ofruby web applications
A developer tool forend-to-end testing ofruby web applications LIE
Basics
Feature: DevCon talk  In order to fill the DevCon6 schedule  As a Cucumber user  I want to talk about BDD with Cucumber  S...
Feature: DevCon talk  In order to fill the DevCon6 schedule  As a Cucumber user  I want to talk about BDD with Cucumber  S...
Feature: DevCon talk  In order to fill the DevCon6 schedule  As a Cucumber user  I want to talk about BDD with Cucumber  S...
Feature: DevCon talk  In order to fill the DevCon6 schedule  As a Cucumber user  I want to talk about BDD with Cucumber  S...
Feature: DevCon talk  In order to fill the DevCon6 schedule  As a Cucumber user  I want to talk about BDD with Cucumber  S...
Feature: Withdraw cash from account  Scenario: Successful withdrawal    Given I have £100 in my account    When I request ...
$ cucumber withdraw_cash.featureFeature: Withdraw cash from account  Scenario: Successful withdrawal        #   withdraw_c...
Scenario: Successful login  Given a user "Fred" with password "secret"  When I go to the login page  And I fill in "User n...
Scenario: Adding a CaaS Linux Service in a production (or test) environment  Given a fred production environment exists  A...
Scenario: Successful login  Given a user "Fred" with password "secret"  When I go to the login page  And I fill in "User n...
Scenario: User is greeted upon login  Given the user "Fred" has an account  When he logs in  Then he should see "Welcome, ...
Given /^the user "(.*?)" has an account$/ do |name|  @user = User.find_or_create_by_name name, password: "secret"endWhen /...
Scenario: User is greeted upon login  Given the user "Fred" has an account  When he logs in  Then he should see "Welcome, ...
Feature: My awesome system Scenario: Using the system   Given the system exists   When I use it   Then everything should w...
A developer tool forend-to-end testingof web applications
A developer tool for      LIEend-to-end testingof web applications
Scenario: create a dir  Given a directory named "foo/bar"  When I run `file foo/bar`  Then the stdout should contain "foo/...
A tool for end-to-end testing of web   applications
A tool for end-to-end testing of web                 LIE   applications
More feature  … er … features
Feature: Posting messages to friends Scenario: Posting a text message   Given I am logged in   When I post a text message ...
Feature: Posting messages to friends Scenario: Posting a text message   Given I am logged in   When I post a text message ...
Feature: Posting messages to friends  Background:    Given I am logged in Scenario: Posting a text message   When I post a...
Scenario:  When I add 1 widget to my order  And I add 5 doodahs to my order  And I add 2 thingummies to my order  Then my ...
Scenario:  When I add the   following to my order:    | Quantity |   Item      |    | 1        |   widget    |    | 5     ...
Scenario: Simple addition  When I calculate 2 + 2  Then the answer should be 4 When I calculate 10 + 5 Then the answer sho...
Scenario Outline: Simple arithmetic  When I calculate <first> <operation> <second>  Then the answer should be <answer> Exa...
http://www.flickr.com/photos/yogendra174/4665988849
# language: frFonctionnalité: Addition  Afin de financer mon bonus avec largent des pigeons  En tant que trader  Je souhai...
# language: esCaracterística: adición  Para evitar hacer errores tontos  Como un matemático idiota  Quiero saber la suma d...
# language: deFunktionalität: Addition  Um dumme Fehler zu vermeiden  möchte ich als Matheidiot  die Summe zweier Zahlen g...
# language: en-lolOH HAI: STUFFING MISHUN:   CUCUMBR   I CAN   HAZ IN TEH BEGINNIN 3 CUCUMBRZ   WEN I   EAT 2 CUCUMBRZ   D...
Getting the mostout of Cucumber
http://www.flickr.com/photos/oskay/2156888497
Given /^the user "(.*?)" has an account$/ do |name|  @user = User.find_or_create_by_name name, password: "secret"endGiven ...
Given /^the user "(.*?)" has an account$/ do |name|  @user = User.find_or_create_by_name name, password: "secret"endGiven ...
module LoginSteps  def login(name, password)    visit "/login"    fill_in "User name", with: name    fill_in "Password", w...
http://tooky.co.uk/2013/01/18/cucumber-and-full-stack-testing.html
http://blog.mattwynne.net/2012/05/31/hexagonal-rails-objects-values-and-hexagons/
A tool forend-to-end testing  of applications
A tool forend-to-end testing     LIE  of applications
A tool for testing  applications
A tool for testingRELY               TI  applications        N            EN HER          OT EIT            UE         TR
http://www.flickr.com/photos/elycefeliz/3224486233
Made-up statistics                        Identifying scenarios                                 25%   Automated tests     ...
$ cucumber talk.featureFeature: DevCon talk  In order to fill the DevCon6 schedule  As a Cucumber user  I want to talk abo...
http://www.flickr.com/photos/erix/3780828260
BDD with cucumber
BDD with cucumber
BDD with cucumber
Upcoming SlideShare
Loading in...5
×

BDD with cucumber

4,550

Published on

Slides from BT DevCon6

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,550
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
39
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "BDD with cucumber"

  1. 1. Behaviour-drivendevelopment with Cucumber Kerry Buckley BT DevCon6, 4 February 2013 http://www.flickr.com/photos/yogendra174/4665988849
  2. 2. A developer tool forend-to-end testing ofruby web applications
  3. 3. A developer tool forend-to-end testing ofruby web applications LIE
  4. 4. Basics
  5. 5. Feature: DevCon talk In order to fill the DevCon6 schedule As a Cucumber user I want to talk about BDD with Cucumber Scenario: "BDD with Cucumber" talk Given I have managed to prepare a talk And there are people there to hear it When I give the talk Then the audience should learn something
  6. 6. Feature: DevCon talk In order to fill the DevCon6 schedule As a Cucumber user I want to talk about BDD with Cucumber Scenario: "BDD with Cucumber" talk Given I have managed to prepare a talk And there are people there to hear it When I give the talk Then the audience should learn something
  7. 7. Feature: DevCon talk In order to fill the DevCon6 schedule As a Cucumber user I want to talk about BDD with Cucumber Scenario: "BDD with Cucumber" talk Given I have managed to prepare a talk And there are people there to hear it When I give the talk Then the audience should learn something
  8. 8. Feature: DevCon talk In order to fill the DevCon6 schedule As a Cucumber user I want to talk about BDD with Cucumber Scenario: "BDD with Cucumber" talk Given I have managed to prepare a talk And there are people there to hear it When I give the talk Then the audience should learn something
  9. 9. Feature: DevCon talk In order to fill the DevCon6 schedule As a Cucumber user I want to talk about BDD with Cucumber Scenario: "BDD with Cucumber" talk Given I have managed to prepare a talk And there are people there to hear it When I give the talk Then the audience should learn something
  10. 10. Feature: Withdraw cash from account Scenario: Successful withdrawal Given I have £100 in my account When I request a withdrawal of £20 Then I should receive £20 And my balance should be £80
  11. 11. $ cucumber withdraw_cash.featureFeature: Withdraw cash from account Scenario: Successful withdrawal # withdraw_cash.feature:3 Given I have £100 in my account # withdraw_cash.feature:4 When I request a withdrawal of £20 # withdraw_cash.feature:5 Then I should receive £20 # withdraw_cash.feature:6 And my balance should be £80 # withdraw_cash.feature:71 scenario (1 undefined)4 steps (4 undefined)0m0.002sYou can implement step definitions for undefined steps with these snippets:Given /^I have £(d+) in my account$/ do |arg1| pending # express the regexp above with the code you wish you hadend...
  12. 12. Scenario: Successful login Given a user "Fred" with password "secret" When I go to the login page And I fill in "User name" with "Fred" And I fill in "Password" with "secret" And I press "Log in" Then I should see "Welcome, Fred"
  13. 13. Scenario: Adding a CaaS Linux Service in a production (or test) environment Given a fred production environment exists And I am on the last deployment page When I select "CaaS Linux Service" from "Add a new" And I press "Add service" And I fill in the following: | Role | FTP Server | | Application Installed Software | None | And I select "SC3 (redside)" from "Security Domain" And I select "2" from "Virtual CPUs" And I select "2" from "Virtual Memory" And I select "OEL 5u6 32bit" from "Operating System" And I select "None" from "MaaS(EMB) MQ Client" And I select "None" from "Oracle Client" And I check "Netbackup Client" And I check "XFB Client" And I check "BT Hunter Client" And I check "BTBPTM Client" And I check "Web Tier" And I press "Save" Then I should be on the last deployment page And I should see "Service saved" And I should see ...
  14. 14. Scenario: Successful login Given a user "Fred" with password "secret" When I go to the login page And I fill in "User name" with "Fred" And I fill in "Password" with "secret" And I press "Log in" Then I should see "Welcome, Fred"
  15. 15. Scenario: User is greeted upon login Given the user "Fred" has an account When he logs in Then he should see "Welcome, Fred"
  16. 16. Given /^the user "(.*?)" has an account$/ do |name| @user = User.find_or_create_by_name name, password: "secret"endWhen /^he logs in$/ do visit "/login" fill_in "User name", with: @user.name fill_in "Password", with: @user.password click_button "Log in"endThen /^he should see "(.*?)"$/ do |text| page.should have_content(text)end
  17. 17. Scenario: User is greeted upon login Given the user "Fred" has an account When he logs in Then he should see "Welcome, Fred"Scenario: Secure pages require login When I visit a secure page as a guest Then I should be asked to log in When I log in with a valid account Then I should see the secure page
  18. 18. Feature: My awesome system Scenario: Using the system Given the system exists When I use it Then everything should work perfectly
  19. 19. A developer tool forend-to-end testingof web applications
  20. 20. A developer tool for LIEend-to-end testingof web applications
  21. 21. Scenario: create a dir Given a directory named "foo/bar" When I run `file foo/bar` Then the stdout should contain "foo/bar: directory"Scenario: create a file Given a file named "foo/bar/example.txt" with: """ hello world """ When I run `cat foo/bar/example.txt` Then the output should contain exactly "hello world"
  22. 22. A tool for end-to-end testing of web applications
  23. 23. A tool for end-to-end testing of web LIE applications
  24. 24. More feature … er … features
  25. 25. Feature: Posting messages to friends Scenario: Posting a text message Given I am logged in When I post a text message Then my friends should see my message Scenario: Posting a photo Given I am logged in When I post a photo Then my friends should see a thumbnail of my photo And clicking the thumbnail should show the photo
  26. 26. Feature: Posting messages to friends Scenario: Posting a text message Given I am logged in When I post a text message Then my friends should see my message Scenario: Posting a photo Given I am logged in When I post a photo Then my friends should see a thumbnail of my photo And clicking the thumbnail should show the photo
  27. 27. Feature: Posting messages to friends Background: Given I am logged in Scenario: Posting a text message When I post a text message Then my friends should see my message Scenario: Posting a photo When I post a photo Then my friends should see a thumbnail of my photo And clicking the thumbnail should show the photo
  28. 28. Scenario: When I add 1 widget to my order And I add 5 doodahs to my order And I add 2 thingummies to my order Then my basket total should be £12.34
  29. 29. Scenario: When I add the following to my order: | Quantity | Item | | 1 | widget | | 5 | doodah | | 2 | thingummy | Then my basket total should be £12.34
  30. 30. Scenario: Simple addition When I calculate 2 + 2 Then the answer should be 4 When I calculate 10 + 5 Then the answer should be 15Scenario: Simple multiplication When I calculate 2 * 2 Then the answer should be 4 When I calculate 6 * 7 Then the answer should be 42
  31. 31. Scenario Outline: Simple arithmetic When I calculate <first> <operation> <second> Then the answer should be <answer> Examples: | first | operation | second | answer | | 2 | + | 2 | 4 | | 10 | + | 5 | 15 | | 2 | * | 2 | 4 | | 6 | * | 7 | 42 |
  32. 32. http://www.flickr.com/photos/yogendra174/4665988849
  33. 33. # language: frFonctionnalité: Addition Afin de financer mon bonus avec largent des pigeons En tant que trader Je souhaite pouvoir additionner 2 chiffres Plan du Scénario: Addition de produits dérivés Soit une calculatrice Etant donné quon tape <a> Et quon tape <b> Lorsquon tape additionner Alors le résultat doit être <somme> Exemples: | a | b | somme | | 2 | 2 | 4 | | 2 | 3 | 5 |
  34. 34. # language: esCaracterística: adición Para evitar hacer errores tontos Como un matemático idiota Quiero saber la suma de los números Esquema del escenario: Sumar dos números Dado que he introducido <entrada_1> en la calculadora Y que he introducido <entrada_2> en la calculadora Cuando oprimo el <botón> Entonces el resultado debe ser <resultado> en la pantalla Ejemplos: | entrada_1 | entrada_2 | botón | resultado | | 20 | 30 | add | 50 | | 2 | 5 | add | 7 | | 0 | 40 | add | 40 |
  35. 35. # language: deFunktionalität: Addition Um dumme Fehler zu vermeiden möchte ich als Matheidiot die Summe zweier Zahlen gesagt bekommen Szenariogrundriss: Zwei Zahlen hinzufügen Angenommen ich habe <Eingabe_1> in den Taschenrechner eingegeben Und ich habe <Eingabe_2> in den Taschenrechner eingegeben Wenn ich <Knopf> drücke Dann sollte das Ergebniss auf dem Bildschirm <Ausgabe> sein Beispiele: | Eingabe_1 | Eingabe_2 | Knopf | Ausgabe | | 20 | 30 | add | 50 | | 2 | 5 | add | 7 | | 0 | 40 | add | 40 |
  36. 36. # language: en-lolOH HAI: STUFFING MISHUN: CUCUMBR I CAN HAZ IN TEH BEGINNIN 3 CUCUMBRZ WEN I EAT 2 CUCUMBRZ DEN I HAS 2 CUCUMBERZ IN MAH BELLY AN IN TEH END 1 CUCUMBRZ KTHXBAI
  37. 37. Getting the mostout of Cucumber
  38. 38. http://www.flickr.com/photos/oskay/2156888497
  39. 39. Given /^the user "(.*?)" has an account$/ do |name| @user = User.find_or_create_by_name name, password: "secret"endGiven /^a logged-in user$/ do @user = User.find_or_create_by_name "Fred", password: "secret" visit "/login" fill_in "User name", :with => @user.name fill_in "Password", :with => @user.password click_button "Log in"endWhen /^he logs in$/ do visit "/login" fill_in "User name", with: @user.name fill_in "Password", with: @user.password click_button "Log in"endThen /^he should see "(.*?)"$/ do |text| page.should have_content(text)end
  40. 40. Given /^the user "(.*?)" has an account$/ do |name| @user = User.find_or_create_by_name name, password: "secret"endGiven /^a logged-in user$/ do @user = User.find_or_create_by_name "Fred", password: "secret" visit "/login" fill_in "User name", :with => @user.name fill_in "Password", :with => @user.password click_button "Log in"endWhen /^he logs in$/ do visit "/login" fill_in "User name", with: @user.name fill_in "Password", with: @user.password click_button "Log in"endThen /^he should see "(.*?)"$/ do |text| page.should have_content(text)end
  41. 41. module LoginSteps def login(name, password) visit "/login" fill_in "User name", with: name fill_in "Password", with: password click_button "Log in" endendWorld(LoginSteps)Given /^a logged in user$/ do @user = User.find_or_create_by_name name, password: "secret" login(@user.name, @user.password)endWhen /^he logs in$/ do login(@user.name, @user.password)end
  42. 42. http://tooky.co.uk/2013/01/18/cucumber-and-full-stack-testing.html
  43. 43. http://blog.mattwynne.net/2012/05/31/hexagonal-rails-objects-values-and-hexagons/
  44. 44. A tool forend-to-end testing of applications
  45. 45. A tool forend-to-end testing LIE of applications
  46. 46. A tool for testing applications
  47. 47. A tool for testingRELY TI applications N EN HER OT EIT UE TR
  48. 48. http://www.flickr.com/photos/elycefeliz/3224486233
  49. 49. Made-up statistics Identifying scenarios 25% Automated tests 35% Agreeing steps 40%
  50. 50. $ cucumber talk.featureFeature: DevCon talk In order to fill the DevCon6 schedule As a Cucumber user I want to talk about BDD with Cucumber Scenario: "BDD with Cucumber" talk # talk.feature:6 Given I have managed to prepare my talk on time # talk_steps.rb:1 And there are people there to hear it # talk_steps.rb:4 When I give the talk # talk_steps.rb:7 Then the audience should learn something # talk_steps.rb:101 scenario (1 passed)4 steps (4 passed)0m0.002s
  51. 51. http://www.flickr.com/photos/erix/3780828260
  1. A particular slide catching your eye?

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

×