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.

Enabling agile devliery through enabling BDD in PHP projects

2,993 views

Published on

What is the purpose of BDD and how it fits into the Agile development? If you ever wondered what are the benefits of BDD or why should you care about tools like Behat or PhpSpec, this talk will try to guide you through the reasoning and goals of modern Agile practices and tools in PHP.

Published in: Technology

Enabling agile devliery through enabling BDD in PHP projects

  1. 1. Enabling Agile Through enabling BDD in PHP projects
  2. 2. Who? BDD Evangelist ! Creator of Behat, Mink, PhpSpec2, Prophecy ! Contributor to Symfony2, Composer ! Host of the “Elephant in the Room” podcast
  3. 3. BDD
  4. 4. – me, this month BDD is a tool to bring structure into the agile processes
  5. 5. Agile process Out-of-the box
  6. 6. Agile process Out-of-the box
  7. 7. BDD In the Agile process
  8. 8. BDD is the agile enabler
  9. 9. How does it enable Agile?
  10. 10. Requirements Analysis Design Development Testing 9 months 3 m 2 m 12 m ... [Royce 1970]
  11. 11. Most of the cost in software development is in the feedback delay
  12. 12. Lets reduce feedback delay
  13. 13. Requirements Acceptance Testing Coding Refactoring Weeks Minutes [Beck & Cunningham 1996-99]
  14. 14. Requirements Acceptance Testing ? Coding Refactoring [North 2003] Weeks Minutes
  15. 15. Lets clarify design intentions
  16. 16. Requirements Acceptance Specification Implementation Refactoring [North 2003] Weeks Minutes
  17. 17. Lets clarify planning intentions
  18. 18. Adding value What do you mean? Specification Implementation Refactoring [North 2003] Weeks Minutes
  19. 19. Adding value What do you mean? Specification Implementation Refactoring [North 2003]
  20. 20. Adding value What do you mean? Specification Implementation Refactoring [North 2003]
  21. 21. StoryBDD SpecBDD [North 2003] Adding value What do you mean? Specification Implementation Refactoring
  22. 22. Behat PhpSpec [North 2003] Adding value What do you mean? Specification Implementation Refactoring
  23. 23. StoryBDD
  24. 24. StoryBDD looks like a functional TDD to the people from the outside of the BDD community, but it’s a simple confusion.
  25. 25. We are not testing that application functions as we (developers) expect it to, but instead we’re testing that it fulfils our client business needs.
  26. 26. Some applications could easily fulfil developers expectations and still not being able to cover business needs.
  27. 27. You might think about StoryBDD as a technique to teach your clients about testing. In reality it's a tool to teach you about your client business.
  28. 28. User-story • Narrative • Business rules • Communication • Acceptance criteria
  29. 29. User-story • Narrative • Business rules == AC • Communication
  30. 30. User-story • Narrative • Business rules == AC • Comm == Examples
  31. 31. User-story • Narrative • Business rules • Comm == Examples == AC
  32. 32. StoryBDD splits every feature in your project into the 3 separate layers.
  33. 33. Each new layer adds more information to the table.
  34. 34. 1 2 3 narrative possible scenarios scenario details
  35. 35. 1 2 3 possible scenarios scenario details Feature: Authorisation In order to get access to the shopping history As a frequent buyer I need to be able to authenticate
  36. 36. Feature: Authorisation In order to get access to the shopping history As a frequent buyer I need to be able to authenticate 1 2 3scenario details Scenario: Successfully authenticating with correct credentials
  37. 37. Feature: Authorisation In order to get access to the shopping history As a frequent buyer I need to be able to authenticate 1 2 3 Scenario: Successfully authenticating with correct credentials Given there is a user “everzet” with password “123” And I am on the login page When I fill in “username” with “everzet” And I fill in “password” with “123” And I press “login” Then I should see “Hello, everzet” !
  38. 38. Feature: Authorisation In order to get access to the shopping history As a frequent buyer I need to be able to authenticate 1 2 3 Example: Successfully authenticating with correct credentials Given there is a user “everzet” with password “123” And I am on the login page When I fill in “username” with “everzet” And I fill in “password” with “123” And I press “login” Then I should see “Hello, everzet” !
  39. 39. Structure In the Agile process
  40. 40. StoryBDD forces you to answer questions you did not know you need to ask.
  41. 41. 1. Why? aka: how to prioritise my backlog
  42. 42. Feature: Authorisation Why might your users want this feature?
  43. 43. Feature: Authorisation In order to get access to the shopping history
  44. 44. Feature: Authorisation In order to get access to the shopping history Who is mostly interested in this feature?
  45. 45. Feature: Authorisation In order to get access to the shopping history As a frequent buyer
  46. 46. Feature: Authorisation In order to get access to the shopping history As a frequent buyer How can you help him get this value?
  47. 47. Feature: Authorisation In order to get access to the shopping history As a frequent buyer I need to be able to authenticate
  48. 48. Feature: Authorisation In order to get access to the shopping history As a frequent buyer I need to be able to authenticate benefit beneficiar
  49. 49. Feature: Authorisation In order to get access to the shopping history As a frequent buyer I need to be able to authenticate Feature: … In order to … As a … I need to … Feature: … In order to … As a … I need to … Feature: … In order to … As a … I need to … benefit beneficiar
  50. 50. SELECT f.* as sprint FROM ‘/features’ as f ORDER BY f.role, f.benefit LIMIT 10 PSEUDOAgileQL
  51. 51. 2. What do you mean? aka: defining done through examples
  52. 52. How much “done” is “done”?
  53. 53. How much of the feature should be delivered?
  54. 54. Scenario: Successfully authenticating with correct credentials Given there is a user “everzet” with password “123” And I am on the login page When I fill in “username” with “everzet” And I fill in “password” with “123” And I press “login” Then I should see “Hello, everzet” !
  55. 55. Scenario: Successfully authenticating with correct credentials Given there is a user “everzet” with password “123” And I am on the login page When I fill in “username” with “everzet” And I fill in “password” with “123” And I press “login” Then I should see “Hello, everzet” ! Given defines initial context
  56. 56. Scenario: Successfully authenticating with correct credentials Given there is a user “everzet” with password “123” And I am on the login page When I fill in “username” with “everzet” And I fill in “password” with “123” And I press “login” Then I should see “Hello, everzet” ! When defines a user action (or state transition)
  57. 57. Scenario: Successfully authenticating with correct credentials Given there is a user “everzet” with password “123” And I am on the login page When I fill in “username” with “everzet” And I fill in “password” with “123” And I press “login” Then I should see “Hello, everzet” ! Then defines an expected outcome
  58. 58. Scenario: Successfully authenticating with correct credentials Given there is a user “everzet” with password “123” And I am on the login page When I fill in “username” with “everzet” And I fill in “password” with “123” And I press “login” Then I should see “Hello, everzet” ! And, But add more context, actions or outcomes
  59. 59. Scenario: Successfully authenticating with correct credentials Given there is a user “everzet” with password “123” And I am on the login page When I fill in “username” with “everzet” And I fill in “password” with “123” And I press “login” Then I should see “Hello, everzet” !
  60. 60. 3. When are we done? aka: closing feedback loop
  61. 61. assertEquals(Your Feature, Your App)
  62. 62. Setup • Dump your sprint features into text files • Put those text files into the `features/` folder inside project • Install behat (via composer or behat.phar) • Initialize behat test suite by running `bin/behat —init`
  63. 63. Context <?php ! use BehatBehatContextClosuredContextInterface, BehatBehatContextTranslatedContextInterface, BehatBehatContextBehatContext, BehatBehatExceptionPendingException; use BehatGherkinNodePyStringNode, BehatGherkinNodeTableNode; ! class FeatureContext extends BehatContext { }
  64. 64. First run $> bin/behat ... You can implement step definitions for undefined steps with these snippets: ! /** * @Then I should see :arg1 */ public function iShouldSee($arg1) { throw new PendingException(); } ...
  65. 65. Append snippets $> bin/behat --append-snippets
  66. 66. Feedback loop $> bin/behat ! Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage TODO: write pending definition When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
  67. 67. Stories Examples Describe Implement Design
  68. 68. Stories Examples Describe Implement Design
  69. 69. Colour it red.
  70. 70. Making it fail /** * @Given /^I am on the homepage$/ */ public function iAmOnTheHomepage() { $crawler = new SomeCrawlerLibCrawler(); $crawler->goto(“http://localhost:8080/”); if (200 !== $crawler->getCurrentStatusCode()) { throw new RuntimeException(‘Can not open homepage’); } }
  71. 71. Making it fail $> bin/behat ! Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage Can not open homepage (RuntimeException) When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
  72. 72. Stories Examples Describe Implement Design
  73. 73. Change the message As quickly as you can
  74. 74. Change the message $> bin/behat ! Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage Can not open homepage (RuntimeException) When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
  75. 75. Change the message $> bin/behat ! Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage Route … not found (FrameworkException) When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
  76. 76. Change the message $> bin/behat ! Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage Template … not found (FrameworkException) When I follow “sign up” And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
  77. 77. Change the message $> bin/behat ! Feature: registration in order to maintain my shopping history as a site visitor i need to be able to register on this site ! Scenario: Successful registration when visitor provides all the required info Given I am on the homepage When I follow “sign up” TODO: write pending definition And I fill in registration form And I submit it Then I should be successfully registered And I should be on the homepage again
  78. 78. Read more at behat.org
  79. 79. Stories Examples Describe Implement Design Spec-BDD
  80. 80. Stories Examples Describe Implement Design Spec-BDD
  81. 81. Stories Examples Describe Implement Design Spec-BDD
  82. 82. Stories Examples Describe Implement Design
  83. 83. Read more at phpspec.net
  84. 84. That’s all nice theoretical stuff
  85. 85. http://inviqa.com/careers
  86. 86. Thank you!

×