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.

PHPNW16 Matt Brunt - BDD & Behat

806 views

Published on

Stories? Scenarios? BDD? Are these just more words in the ever-growing list of jargon that developers have to know? Or are they something more important than new terms to memorise?

In this session we'll look at how BDD fits into the software development work-flow, how to tell user stories through features, and how to automate them in Behat.

These techniques will help to ensure you're writing well designed and tested software that focuses on what the users want from a system.

Published in: Technology
  • Be the first to comment

PHPNW16 Matt Brunt - BDD & Behat

  1. 1. @TheMattBrunt BEHAVIOUR DRIVEN DEVELOPMENT & BEHAT TELLING STORIES THROUGH CODE
  2. 2. @TheMattBrunt Senior Software Engineer Viva IT @TheMattBrunt @PHPem
  3. 3. @TheMattBrunt BEFORE WE TALK ABOUT BDD
  4. 4. @TheMattBrunt LET’S QUICKLY TALK ABOUT TESTING
  5. 5. @TheMattBrunt TDD VS BDD
  6. 6. @TheMattBrunt BDD IS TDD ‘DONE RIGHT’ IT’S OFTEN SAID THAT…
  7. 7. @TheMattBrunt TDD IS BUILDING THE THING RIGHT
  8. 8. @TheMattBrunt BDD IS BUILDING THE RIGHT THING
  9. 9. @TheMattBrunt BEHAVIOUR DRIVEN DEVELOPMENT
  10. 10. @TheMattBrunt WE’LL BE LOOKING AT SCENARIO BDD
  11. 11. @TheMattBrunt BDD IS A SECOND-GENERATION, OUTSIDE-IN, PULL- BASED, MULTIPLE-STAKEHOLDER, MULTIPLE- SCALE, HIGH-AUTOMATION, AGILE METHODOLOGY. DAN NORTH http://dannorth.net/whats-in-a-story/
  12. 12. @TheMattBrunt SECOND-GENERATION BREAK DOWN
  13. 13. @TheMattBrunt MULTIPLE-STAKEHOLDER BREAK DOWN
  14. 14. @TheMattBrunt AGILE METHODOLOGY BREAK DOWN
  15. 15. @TheMattBrunt MULTIPLE STAKEHOLDERS
  16. 16. @TheMattBrunt CONVERSATIONS ARE KEY
  17. 17. @TheMattBrunt HAVING CONVERSATIONS > CAPTURING CONVERSATIONS AUTOMATING CONVERSATIONS>
  18. 18. @TheMattBrunt HAVE CONVERSATIONS BEFORE YOU START WRITING CODE
  19. 19. @TheMattBrunt CAPTURE THE CONVERSATIONS SO YOU CAN USE THEM TO DRIVE DEVELOPMENT
  20. 20. @TheMattBrunt BDD IS THE ART OF USING EXAMPLES IN CONVERSATIONS TO ILLUSTRATE BEHAVIOUR LIZ KEOGH
  21. 21. @TheMattBrunt EXAMPLES ARE ESSENTIAL
  22. 22. @TheMattBrunt SO, HOW DO WE WORK WITH THIS?
  23. 23. @TheMattBrunthttps://github.com/cucumber/cucumber/wiki/Gherkin GHERKIN DSL
  24. 24. @TheMattBrunt HUMAN READABLE GHERKIN IS…
  25. 25. @TheMattBrunt MULTI-LINGUAL SUPPORT TOOLS CAN INCLUDE…
  26. 26. @TheMattBrunt EN-PIRATE INCLUDING https://github.com/Behat/Gherkin/blob/master/i18n.php#L313
  27. 27. @TheMattBrunt KEYWORD BASED GHERKIN IS…
  28. 28. @TheMattBrunt LINE ORIENTED GHERKIN IS…
  29. 29. @TheMattBrunt DOCUMENTATION GHERKIN IS…
  30. 30. @TheMattBrunt AUTOMATION GHERKIN ALLOWS…
  31. 31. @TheMattBrunt DEVELOPERS LOVE AUTOMATION
  32. 32. @TheMattBrunt WRITING STORIES
  33. 33. @TheMattBrunt BE DESCRIPTIVE
  34. 34. @TheMattBrunt FEATURES ARE STORIES
  35. 35. @TheMattBrunt SINGLE FEATURE PER FILE
  36. 36. @TheMattBrunt Feature: As a [role] I want [feature] So that [benefit]
  37. 37. @TheMattBrunt Feature: In order to [achieve value] As a [role] I want [feature] https://lizkeogh.com/2008/05/14/rip-as-a-i-want-so-that/
  38. 38. @TheMattBrunt SCENARIOS
  39. 39. @TheMattBrunt SCENARIOS ARE EXAMPLES
  40. 40. @TheMattBrunt EXAMPLES ARE ESSENTIAL
  41. 41. @TheMattBrunt MULTIPLE SCENARIOS FEATURES CAN HAVE
  42. 42. @TheMattBrunt STEPS
  43. 43. @TheMattBrunt MULTIPLE STEPS SCENARIOS HAVE…
  44. 44. @TheMattBrunt KEYWORDS
  45. 45. @TheMattBrunt GIVEN PUTS THE SYSTEM IN A KNOWN STATE
  46. 46. @TheMattBrunt WHEN DESCRIBE A KEY ACTION
  47. 47. @TheMattBrunt THEN DESCRIBE AN OBSERVABLE OUTCOME
  48. 48. @TheMattBrunt Given I have a “Large T-Shirt” product When I add a “Large T-Shirt” to my basket Then I should have a “Large T-Shirt” in my basket
  49. 49. @TheMattBrunt AND THERE’S ALSO…
  50. 50. @TheMattBrunt BUT THERE’S ALSO…
  51. 51. @TheMattBrunt Given I have a “Large T-Shirt” product that costs £9.99 And I have an empty basket And I am a tax-exempt customer When I add a “Large T-Shirt” to my basket Then I should have a “Large T-Shirt” in my basket And the basket total should be £9.99 But I should not have tax applied to my order
  52. 52. @TheMattBrunt STORY STRUCTURE: THE MAKEUP OF A FEATURE FILE
  53. 53. @TheMattBrunt Feature: As a customer I want to be able to add products to my basket So that I can have a gift for my partner Scenario: I can add a product to the basket Given I have a "Large T-Shirt" product When I add a “Large T-Shirt” to my basket Then I should have a “Large T-Shirt” in my basket FEATURE
  54. 54. @TheMattBrunt SCENARIO Feature: As a customer I want to be able to add products to my basket So that I can have a gift for my partner Scenario: I can add a product to the basket Given I have a "Large T-Shirt" product When I add a “Large T-Shirt” to my basket Then I should have a “Large T-Shirt” in my basket
  55. 55. @TheMattBrunt STEP Feature: As a customer I want to be able to add products to my basket So that I can have a gift for my partner Scenario: I can add a product to the basket Given I have a "Large T-Shirt" product When I add a “Large T-Shirt” to my basket Then I should have a “Large T-Shirt” in my basket
  56. 56. @TheMattBrunt THIS IS GREAT, BUT HOW DO WE (DEVELOPERS) WORK WITH IT?
  57. 57. @TheMattBrunt STEP DEFINITIONS
  58. 58. @TheMattBrunt Given I have a “Large T-Shirt” product When I add that product to my basket Then I should see that product in my basket
  59. 59. @TheMattBrunt ARGUMENTS
  60. 60. @TheMattBrunt
  61. 61. @TheMattBrunt TRANSFORMERS
  62. 62. @TheMattBrunt
  63. 63. @TheMattBrunt
  64. 64. @TheMattBrunt TAGS
  65. 65. @TheMattBrunt
  66. 66. @TheMattBrunt HOOKS
  67. 67. @TheMattBrunt BEFORE & AFTER SUITES, FEATURES, SCENARIOS, STEPS HOOKS
  68. 68. @TheMattBrunt
  69. 69. @TheMattBrunt SUITES & PROFILES
  70. 70. @TheMattBrunt TEST FEATURES WITH DIFFERENT CONFIGURATIONS SUITES ALLOW YOU TO…
  71. 71. @TheMattBrunt THEY CAN USE THE SAME FEATURE FILES. OR THEY CAN USE DIFFERENT FEATURE FILES FOR EXAMPLE:
  72. 72. @TheMattBrunt YOU CAN USE THE SAME FEATURE FILE TO TEST DIFFERENT IMPLEMENTATIONS WITH SUITES AND TAGS…
  73. 73. @TheMattBrunt
  74. 74. @TheMattBrunt
  75. 75. @TheMattBrunt YOU CAN HAVE A UI SUITE THAT USES DIFFERENT STEP DEFINITIONS THAN A SERVICE / DOMAIN / LOWER LEVEL SUITE FOR EXAMPLE:
  76. 76. @TheMattBrunt
  77. 77. @TheMattBrunt
  78. 78. @TheMattBrunt YOU CAN CHANGE IMPLEMENTATION WITHOUT CHANGING YOUR DOCUMENTED BUSINESS RULES WITH SUITES AND TAGS…
  79. 79. @TheMattBrunt THIS IS WHERE THE POWER LIES FOR ME…
  80. 80. @TheMattBrunt IMPLEMENTATION CHANGES MORE FREQUENTLY THAN BUSINESS RULES
  81. 81. @TheMattBrunt WRITING A GOOD STORY
  82. 82. @TheMattBrunt Scenario: I can add a product to my basket Given I am on the “/product/1” page When I press “Add to basket” Then I should see “Playstation 4” And I should see £250 BAD STORY
  83. 83. @TheMattBrunt Scenario: I can add a single product to my basket Given I have a “Playstation 4” that costs £250 When I add the “Playstation 4” to my basket Then I should have 1 product in my basket And the basket total should be £250 BETTER STORY
  84. 84. @TheMattBrunt Scenario: I can add a product to my basket Given I am on the “/product/1” page When I press “Add to basket” Then I should see “Playstation 4” And I should see £250 WHAT HAPPENS WHEN THE UI CHANGES TO SAY “ADD TO CART”?
  85. 85. @TheMattBrunt DON’T WRITE IMPLEMENTATION IN FEATURES
  86. 86. @TheMattBrunt IN SUMMARY
  87. 87. @TheMattBrunt CONVERSATIONS. CONVERSATIONS. CONVERSATIONS. CONVERSATIONS. CONVERSATIONS.
  88. 88. @TheMattBrunt STORIES TOLD BY REAL WORLD EXAMPLES. USER STORIES AS REQUIREMENTS. INVOLVE MULTIPLE STAKEHOLDERS. WRITE FEATURES BEFORE CODE. WRITE FEATURES WITHOUT IMPLEMENTATION.
  89. 89. @TheMattBrunt BEGINNING: HAVE A CONVERSATION, CAPTURE THAT CONVERSATION MIDDLE: AUTOMATE AND IMPLEMENT THAT CONVERSATION END: HAPPY STAKEHOLDERS AND WELL BUILT SOFTWARE
  90. 90. @TheMattBrunt LINKS & READING https://cucumber.io/docs https://adamcod.es/2014/05/15/test-doubles-mock-vs-stub.html https://github.com/cucumber/cucumber/wiki/Gherkin http://dannorth.net/whats-in-a-story/ http://dannorth.net/introducing-bdd/ http://lizkeogh.com/category/bdd/ http://lizkeogh.com/2014/01/22/using-bdd-with-legacy-systems/ http://inviqa.com/insights/bdd-guide https://cucumber.io/blog/2015/03/24/single-source-of-truth https://github.com/Behat/Gherkin/blob/master/i18n.php#L313
  91. 91. @TheMattBrunt THANKS FOR LISTENING
  92. 92. @TheMattBrunt @TheMattBrunt @PHPem matt@mfyu.co.uk https://joind.in/talk/7c94c

×