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

Cucumber: It's about Talking not Testing

Cucumber: It's about Talking not Testing

Many people use Cucumber purely as an end-to-end testing tool, and often wonder why they’re bothering to use it over something like Steak: they reason that if they’re the only ones reading the feature files, why bother having the plain text features? Others find that the cost of maintaining Cucumber features after a while outweighs the benefits of using them, and stop using it altogether.

Both these conclusions stem from seeing cucumber purely as a testing tool: whereas it’s actually an extraordinarily powerful communication tool designed to facilitate the discussion of behaviour between those to write code and those who don’t, and only incidentally a testing tool.

Learn about a proven and powerful way to use Cucumber which leads to maintainable code, features your customer actually reads, clearer communication and understanding on your project, and as a bonus ensures your code behaves correctly over time.

2687ad35ad8b93df96c5521a86c7101c?s=128

chrismdp

June 29, 2012
Tweet

More Decks by chrismdp

Other Decks in Programming

Transcript

  1. Cucumber It’s about talking not testing Chris Parsons (@chrismdp) Friday,

    29 June 12
  2. GardenApp 1.0 Friday, 29 June 12

  3. Kick off meeting Friday, 29 June 12

  4. Friday, 29 June 12

  5. Friday, 29 June 12

  6. Feature: User orders plant As a user of the website,

    I want to place an order on the website, so that I can order a plant through the website Scenario: User orders plant Given there is a plant with name: “Plant 1”, price: “£1”, size: “large”, foliage: “foliage 1” When I visit the homepage And I click on “Plant 1” And I click “Add” Friday, 29 June 12
  7. And I fill in “City” with “City 1” And I

    fill in “Postcode” with “SW1A 1AA” And I click “Continue” And I click “Continue” And I fill in “Card number” with “1234 1234 1234 1234” And I fill in “Expiry date” with “00/00” And I fill in “Name on Card” with “Name on Card 1” And I fill in “CV2” with “123” And I click “Place Order” Then I should receive an email Friday, 29 June 12
  8. What is Cucumber? Friday, 29 June 12

  9. $ mkdir features $ vim features/ first.feature $ cucumber Friday,

    29 June 12
  10. Myth #1: Cucumber was made for us. Friday, 29 June

    12
  11. Listening Friday, 29 June 12

  12. “So, I’m thinking of a gardening website, where you can

    buy stuff...” Friday, 29 June 12
  13. “...but with a way for those who love gardening to

    make it a whole interactive experience, right?” Friday, 29 June 12
  14. “So gardeners can create like an ‘area’ to put pictures

    of their plants...” Friday, 29 June 12
  15. “...and other gardeners can say what they think, and suggest

    garden layout improvements...” Friday, 29 June 12
  16. “Herp derpety derp derp herp herpity derp website derp herp

    derp buy stuff” Friday, 29 June 12
  17. “...derpety herpity derpety herpity users derp herp social derp?” Friday,

    29 June 12
  18. “Users herp derp account derpety users#show derp photos (hmm, EC2

    storage; which gem? Add day to estimate)” Friday, 29 June 12
  19. “...herp herpity herp derp ratings derpity comments” Friday, 29 June

    12
  20. Myth #2: Cucumber features capture everything. Friday, 29 June 12

  21. What is a feature? Friday, 29 June 12

  22. The feature is not the feature. Friday, 29 June 12

  23. Friday, 29 June 12

  24. Reminder of communication Friday, 29 June 12

  25. Record of communication Friday, 29 June 12

  26. Reek Detector for communication Friday, 29 June 12

  27. Myth #3: Cucumber is a testing tool. Friday, 29 June

    12
  28. “Why?” not “How?” Friday, 29 June 12

  29. Feature: User orders plant As a user of the website,

    I want to place an order on the website, so that I can order a plant through the website Scenario: User orders plant Given there is a plant with name: “Plant 1”, price: “£1”, size: “large”, foliage: “foliage 1” When I visit the homepage And I click on “Plant 1” And I click “Add” Friday, 29 June 12
  30. And I fill in “City” with “City 1” And I

    fill in “Postcode” with “SW1A 1AA” And I click “Continue” And I click “Continue” And I fill in “Card number” with “1234 1234 1234 1234” And I fill in “Expiry date” with “00/00” And I fill in “Name on Card” with “Name on Card 1” And I fill in “CV2” with “123” And I click “Place Order” Then I should receive an email Friday, 29 June 12
  31. Given /there (?:is|are) (a|\d+) (\w+) with ((\w+): (\w+) )+$/ do

    |count, name, fields| count = count == “a” ? 1 : count.to_i params = {} fields.each do |field| params[field[0]] = field[1] end count.times { name.classify.create! (params) } end Friday, 29 June 12
  32. ....FF...FFFUUU Friday, 29 June 12

  33. GardenApp 2.0 Friday, 29 June 12

  34. Ubiquitous Language Friday, 29 June 12

  35. “So, I’m thinking of a gardening website, where you can

    buy stuff...” Friday, 29 June 12
  36. “...but with a way for those who love gardening to

    make it a whole interactive experience, right?” Friday, 29 June 12
  37. “So gardeners can create like an ‘area’ to put pictures

    of their plants...” Friday, 29 June 12
  38. “...and other gardeners can say what they think, and suggest

    garden layout improvements...” Friday, 29 June 12
  39. Feature: User orders plant As Gareth the aspiring gardener, I

    want to buy plants I’ve seen shared on other gardeners uploaded layouts, so that I can improve my own garden with ideas from others Friday, 29 June 12
  40. Scenario: Gareth buys plants When “Gareth” buys a recommended plant

    Then the order should be placed Friday, 29 June 12
  41. Scenario: Gareth supplies incorrect information When “Gareth” enters incorrect information

    during a purchase Then he is shown an appropriate error And the order does not get placed Friday, 29 June 12
  42. When /^“(.+)” buys a recommended plant$/ do |name| place_order(user_for(name)) end

    Then /^the order should be placed$/ do |name| check_order_placed(user_for(name)) end Friday, 29 June 12
  43. When /^“(.+)” enters incorrect information during a purchase$/ do |name|

    place_order(user_for(name)) do fill_in :credit_card, :with => “bad” end end Friday, 29 June 12
  44. def user_for(name) User.find_by_name(name) || User.create(:name => name) end def place_order(user)

    visit order_path fill_in :name, :with => user.name yield if block_given? click_button “Submit” end Friday, 29 June 12
  45. You don’t have to use it! Friday, 29 June 12

  46. Are we really listening? Friday, 29 June 12

  47. Are we just checking it works? Friday, 29 June 12

  48. Friday, 29 June 12

  49. Coupon Code: SCOTRUBY for 20% off Friday, 29 June 12

  50. Chris Parsons @chrismdp http://bddkickstart.com Friday, 29 June 12