BDD with Behat

6,213 views

Published on

A talk I gave at pdxphp about using Behat for Behavior Driven Development

Published in: Technology
3 Comments
15 Likes
Statistics
Notes
No Downloads
Views
Total views
6,213
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
102
Comments
3
Likes
15
Embeds 0
No embeds

No notes for slide

BDD with Behat

  1. 1. BDD with Behat
  2. 2. Who am I? Richard D Shank [email_address] @IamPersistent Freelancer Symfony2 developer Wanna be rock star
  3. 3. What is BDD? Behavior Driven Development
  4. 4. What is BDD? What does that mean?
  5. 5. Testing We know we should do it, why don't we? <ul><li>It takes too much time
  6. 6. It slows me down
  7. 7. The boss won't let me
  8. 8. I'm not really sure how </li></ul>
  9. 9. Testing <ul><li>Write code
  10. 10. Write tests </li></ul><ul><li>The test is written to match code
  11. 11. It carries the bias of our code
  12. 12. Its just too much trouble </li></ul>
  13. 13. TDD Solution: Test Driven Development
  14. 14. TDD Test written before code <ul><li>Eliminates bias
  15. 15. You know the test will be written </li></ul>
  16. 16. TDD What the hell do I test?
  17. 17. BDD Behavior Driven Development
  18. 18. BDD What makes it different? Its written from the outside in, driven by the business value
  19. 19. BDD How does it work? You tell a story When a customer clicks on a blue widget, it is added to their shopping cart.
  20. 20. BDD Advantages <ul><li>Clarifies up front what needs to be done
  21. 21. It is written in everyday, spoken language
  22. 22. Anyone can understand and write stories
  23. 23. Makes everyone think about the requirements
  24. 24. It keeps you focused on what is necessary - YAGNI </li></ul>
  25. 25. Gherkin
  26. 26. Behat <ul><li>System to write and test stories
  27. 27. Uses Gherkin syntax
  28. 28. 6 step process
  29. 29. PHP 5.3 </li></ul>
  30. 30. Installation $ pear channel-discover pear.everzet.com $ pear install everzet/behat-beta
  31. 31. File organization
  32. 32. Step 1 - Behavior addition.feature
  33. 33. Step 2 – Object Definition Steps are generated Calculator.php
  34. 34. Step 2 – Object Definition *Writing a stub class is not really the BDD way of doing things, PHP doesn't handle 'method not found' exceptions very well, so the stub class is necessary for PHP
  35. 35. Step 2 – Generate Steps
  36. 36. Step 2 – Step Definition steps/calculator.php
  37. 37. Step 2 – Add support support/env.php
  38. 38. Step 3 - Write a definition
  39. 39. Step 4 – Run it, watch it fail
  40. 40. Step 5 – Write the code
  41. 41. Step 6 – Run it, watch it pass!
  42. 42. Wash, rinse, repeat Keep repeating the process until all tests pass.
  43. 43. Write step for add
  44. 44. Watch it fail
  45. 45. Write the code
  46. 46. Watch it pass
  47. 47. Write step for result
  48. 48. Watch it fail
  49. 49. Write the code
  50. 50. Watch it pass
  51. 51. Unit Testing Does not replace unit testing, It supplements it
  52. 52. More complex
  53. 53. Scenario Outlines
  54. 54. Backgrounds
  55. 55. Hooks
  56. 56. In-step calls
  57. 57. New feature
  58. 58. Learn more http://en.wikipedia.org/wiki/Behavior_Driven_Development http://blog.dannorth.net/introducing-bdd https://github.com/aslakhellesoy/cucumber/wiki http://cukes.info http://everzet.com/Behat https://github.com/everzet/Behat http://www.pragprog.com/titles/achbd/the-rspec-book http://scotland-on-rails.s3.amazonaws.com/1A06_JosephWilk-SOR.mp4

×