Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Executable Requirements with Behaviour-Driven Development and Cucumber - EuroSTAR 2009

5,116 views

Published on

An intro to BDD and Cucumber

Published in: Technology, Design
  • Be the first to comment

Executable Requirements with Behaviour-Driven Development and Cucumber - EuroSTAR 2009

  1. Executable Requirements with BDD and http://cukes.info/ Aslak Hellesøy - Chief Scientist @aslak_hellesoy aslak.hellesoy@gmail.com
  2. BDD: Dual audience Stakeholders Testers Users Programmers
  3. UBIQUITOUS
  4. Outside in
  5. User Story
  6. User Story Sign up In order to avoid manual work participants should be able to sign up on the web
  7. User Story Sign up In order to avoid manual work participants should be able to sign up on the web
  8. User Story Sign up In order to avoid manual work participants should be able to sign up on the web
  9. User Story Sign up In order to avoid manual work participants should be able to sign up on the web
  10. Common understanding of Done
  11. Acceptance
  12. Acceptance Given I am on the signup page And I have filled in the form When I click “sign up” Then I should get email confirm. Given... When... Then...
  13. Acceptance They are examples! Given I am on the signup page And I have filled in the form When I click “sign up” Then I should get email confirm. Given... When... Then...
  14. Acceptance
  15. http://cukes.info/
  16. http://www.flickr.com/photos/twose/887903401/
  17. http://www.flickr.com/photos/twose/887903401/
  18. 80000 downloads http://www.flickr.com/photos/twose/887903401/
  19. 80000 downloads 1550 followers http://www.flickr.com/photos/twose/887903401/
  20. 80000 downloads 1550 followers 180 contributors http://www.flickr.com/photos/twose/887903401/
  21. 80000 downloads 1550 followers 180 contributors 65 wiki pages http://www.flickr.com/photos/twose/887903401/
  22. 80000 downloads 1550 followers 180 contributors 65 wiki pages 40 tools http://www.flickr.com/photos/twose/887903401/
  23. 80000 downloads 1550 followers 180 contributors 65 wiki pages 40 tools 20 screencasts http://www.flickr.com/photos/twose/887903401/
  24. 80000 downloads 1550 followers 180 contributors 65 wiki pages 40 tools 20 screencasts 60 in #cucumber http://www.flickr.com/photos/twose/887903401/
  25. 80000 downloads 1550 followers 180 contributors 65 wiki pages 40 tools 20 screencasts 60 in #cucumber #7 on Github http://www.flickr.com/photos/twose/887903401/
  26. Javascript Next:
  27. Cuke4Duke
  28. Gherkin (language)
  29. # language: en Feature: Division In order to avoid silly mistakes Cashiers must be able to calculate a fraction Scenario: Regular numbers Given I have entered 3 into the calculator And I have entered 2 into the calculator When I press divide Then the result should be 1.5 on the screen
  30. # language: ja : : 3 2 divide 1.5
  31. OH HAI: STUFFING MISHUN: CUCUMBR I CAN HAZ IN TEH BEGINNIN "3" CUCUMBRZ WEN I EAT "2" CUCUMBRZ DEN I HAZ "2" CUCUMBERZ IN MAH BELLY AN IN TEH END "1" CUCUMBRZ KTHXBAI!
  32. # language: no Egenskap: Summering For å slippe å gjøre dumme feil Som en regnskapsfører Vil jeg kunne legge sammen Scenario: to tall Gitt at jeg har tastet inn 5 Og at jeg har tastet inn 7 Når jeg summerer Så skal resultatet være 12
  33. magyar български Bahasa Indonesia català italiano Cymraeg lietuvių kalba русский Česky latviešu Svenska dansk Nederlands Slovensky Deutsch norsk Узбекча English polski Tiếng Việt Australian português LOLCAT română Texan suomi español français ‫עברית‬ eesti keel hrvatski ‫ﺍﻟﻌﺮﺑﻴﺔ‬
  34. features division.feature
  35. $ cucumber features/division.feature # language: en Feature: Division In order to avoid silly mistakes Cashiers must be able to calculate a fraction Scenario: Regular numbers # features/division.feature:6 Given I have entered 3 into the calculator # features/division.feature:7 And I have entered 2 into the calculator # features/division.feature:8 When I press divide # features/division.feature:9 Then the result should be 1.5 on the screen # features/division.feature:10 1 scenario (1 undefined) 4 steps (4 undefined) 0m0.005s
  36. You can implement step definitions for undefined steps with these snippets: Given /^I have entered 3 into the calculator$/ do pending end Given /^I have entered 2 into the calculator$/ do pending end When /^I press divide$/ do pending end Then /^the result should be 1.5 on the screen$/ do pending end If you want snippets in a different programming language, just make sure a file with the appropriate file extension exists where cucumber looks for step definitions.
  37. features division.feature step_definitions calculator_steps.rb
  38. Given /I have entered (d+) into the calculator/ do |n| @calc.push n.to_i end When /I press (w+)/ do |op| @result = @calc.send op end Then /the result should be (.*) on the screen/ do |result| @result.should == result.to_f end
  39. features division.feature step_definitions calculator_steps.rb lib calculator.rb
  40. $ cucumber features/division.feature # language: en Feature: Division In order to avoid silly mistakes Cashiers must be able to calculate a fraction Scenario: Regular numbers # features/division.feature:6 Given I have entered 3 into the calculator # features/step_definitons/calculator_steps.rb:14 And I have entered 2 into the calculator # features/step_definitons/calculator_steps.rb:14 When I press divide # features/step_definitons/calculator_steps.rb:18 Then the result should be 1.5 on the screen # features/step_definitons/calculator_steps.rb:22 1 scenario (1 passed) 4 steps (4 passed) 0m0.005s
  41. Steps & Step Given the secret code is "r g y c" @Given("^the secret code is "([^"]*)"$") public void theSecretCodeIs(String code) { game = new Game(code); }
  42. Scenario Outline Scenario Outline: submit guess Given the secret code is "<code>" When I guess "<guess>" Then the mark should be "<mark>" Examples: | code | guess | mark | | r g y c | r g y c | bbbb | | r g y c | r g c y | bbww | | r g y c | y r g c | bwww | | r g y c | c r g y | wwww |
  43. Multiline args (String) Then aslak.hellesoy@gmail.com should get email """ Hi aslak.hellesoy@gmail.com Congratulations, Cucumberer was accepted. See you at JavaZone! """ @Then("^(.*) should get email$") public void email(String email, String body) { }
  44. Multiline args (Tables) Given the following proposals | email | title | | aslak.hellesoy@gmail.com | Cucumber | | bryan@brynary.com | Webrat | @Given("^the following proposals$") public void proposals(cuke4duke.Table proposals) { }
  45. Background Feature: Notification emails Background: Given the following proposals exist | email | title | | aslak.hellesoy@gmail.com | Cucumber | | bryan@brynary.com | Webrat | Scenario: Approve all Scenario: Reject Webrat
  46. Tags Feature: Take over the world I want it all @spanish @french @english Scenario: Take over Europe @spanish @english Scenario: Take over America @english Scenario: Take over Australia
  47. Tags cucumber -t spanish doit.feature Feature: Take over the world I want it all @spanish @french @english Scenario: Take over Europe @spanish @english Scenario: Take over America @english Scenario: Take over Australia
  48. Tags Feature: Take over the world I want it all @spanish @french @english Scenario: Take over Europe @spanish @english Scenario: Take over America @english Scenario: Take over Australia
  49. Tags cucumber -t ~french doit.feature Feature: Take over the world I want it all @spanish @french @english Scenario: Take over Europe @spanish @english Scenario: Take over America @english Scenario: Take over Australia
  50. Formatters Pretty Progress Profile HTML JUnit Rerun Your Own
  51. http://cukes.info/ @aslak_hellesoy #cucumber

×