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

Presentation for Liverpool Behat UG opening

Presentation for Liverpool Behat UG opening

Konstantin Kudryashov

May 27, 2013
Tweet

More Decks by Konstantin Kudryashov

Other Decks in Technology

Transcript

  1. None
  2. bdd

  3. None
  4. It is a tool to bring a structure into agile

    processes.
  5. None
  6. None
  7. BDD

  8. BDD is agile enabler.

  9. is a BDD enabler

  10. How?

  11. Requirements Analysis Design Develop Test [Royce 1970] 9 months 3

    months 2 months 12 months ...
  12. Most of the cost in software development is in feedback

    delay
  13. Let’s reduce feedback delay

  14. [Beck & Cunningham 1996-99] Refactoring Code Test Requirements Acceptance

  15. Let’s rename a few things

  16. Incremental Design Implement Describe Object Narratives What do you mean

    [North 03]
  17. Incremental Design Implement Describe Object Narratives What do you mean

    StoryBDD TDD
  18. StoryBDD

  19. StoryBDD could look like functional TDD to people from outside

    BDD community, but it’s a lie.
  20. We are not testing that application functions as we (developers)

    expect it to, but instead we’re testing that it fullfils clients business needs.
  21. Some applications could easily fullfill developers expectations and still not

    being able to cover business needs.
  22. You might think about StoryBDD as a technique to teach

    your clients about testing, but in reality it's a tool to teach you about client business.
  23. Exploration OF Domain area

  24. 3 levels of domain exploration

  25. 1 2 3 narrative possible scenarios scenario details

  26. Feature: Authorization In order to get access to the shopping

    history As a frequent buyer I need to be able to authenticate 1 2 3 possible scenarios scenario details
  27. Feature: Authorization In order to get access to the shopping

    history As a frequent buyer I need to be able to authenticate Scenario: Successfully authenticating with correct credentials 1 2 3 scenario details
  28. Feature: Authorization In order to get access to the shopping

    history As a frequent buyer I need to be able to authenticate 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” 1 2 3
  29. Feature: Authorization In order to get access to the shopping

    history As a frequent buyer I need to be able to authenticate Scenario: Successfully authenticating with correct credentials Scenario: Can not authenticate with wrong credentials Scenario: Blocked user can not authenticate, even with correct credentials
  30. Feature: Authorization In order to get access to the shopping

    history As a frequent buyer I need to be able to authenticate user story =>
  31. StoryBDD helps ensuring that development team has understanding of business

    on the same level that client does
  32. StoryBDD helps ensuring that development team has understanding of business

    on the same level that client does And even leveling up client knowledge of his business
  33. How?

  34. by Forcing you business questions to answer

  35. 1. For who?

  36. 1. For who? 2. What?

  37. 1. For who? 2. What? 3. How?

  38. 1. For who? 2. What? 3. How? Why?

  39. example Registration

  40. ” I want visitors to be able to register on

    my website through simple registration form. Your hypothetical client
  41. 1.Who?

  42. 1.Who? users?

  43. 1.Who? users visitors

  44. 1.Who? users visitors 2.Why?

  45. 1.Who? users visitors 2.Why? it’s common?

  46. 1.Who? users visitors 2.Why? it’s common buyings history

  47. Know your client clients!

  48. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site
  49. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site Feature: registration
  50. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site Feature: registration benefit role (benefitiar)
  51. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site Feature: registration benefit role (benefitiar) in order to ... as a ... i need to ... Feature: ... benefit role (benefitiar) in order to ... as a ... i need to ... Feature: ... benefit role (benefitiar) in order to ... as a ... i need to ... Feature: ... benefit role (benefitiar)
  52. in order to ... as a ... i need to

    ... Feature: ... benefit role (benefitiar) in order to ... as a ... i need to ... Feature: ... benefit role (benefitiar) in order to ... as a ... i need to ... Feature: ... benefit role (benefitiar) in order to maintain my shopping history as a site visitor i need to be able to register on this site Feature: registration benefit role (benefitiar) SELECT f.* FROM ‘/features’ as f ORDER BY f.role, f.benefit LIMIT 10 PSEUDOAgileQL
  53. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site Feature: registration
  54. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site Feature: registration Scenario: Successful registration when visitor provides all the required info
  55. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site Feature: registration Scenario: Successful registration when visitor provides all the required info Scenario: Unable to register when visitor misses required info
  56. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site Feature: registration Scenario: Successful registration when visitor provides all the required info Scenario: Unable to register when visitor misses required info Scenario: ...
  57. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site Feature: registration Scenario: Successful registration when visitor provides all the required info Scenario: Unable to register when visitor misses required info Scenario: ... Scenario: ... Scenario: ... Scenario: ... Scenario: ...
  58. in order to maintain my shopping history as a site

    visitor i need to be able to register on this site Feature: registration Scenario: Successful registration when visitor provides all the required info Given I am on homepage And I follow “sign up” When I fill in “email” with “linkedin@example.com” And I fill in “username” with “linkedin” And I fill in “password” with “sha1_without_salt” And I press “register” Then I should see “You have been successfully registered” And I should be on homepage
  59. None
  60. $> vim composer.json { “require-dev”: { “behat/behat”: “~2.4.5”, }, “config”:

    { “bin-dir”: “bin/” } } $> curl http://getcomposer.org/installer | php $> php composer.phar install --dev
  61. $> bin/behat --init +d features +d features/bootstrap +f features/bootstrap/FeatureContext.php

  62. <?php use Behat\Behat\Context\ClosuredContextInterface, Behat\Behat\Context\TranslatedContextInterface, Behat\Behat\Context\BehatContext, Behat\Behat\Exception\PendingException; use Behat\Gherkin\Node\PyStringNode, Behat\Gherkin\Node\TableNode; class

    FeatureContext extends BehatContext { public function __construct(array $parameters) { // Initialize your context here } }
  63. $> bin/behat ... You can implement step definitions for undefined

    steps with these snippets: /** * @When /^I fill in “([^”]+)” with “([^”]+)”$/ */ public function iFillInWith($val1, $val2) { throw new PendingException(); } ...
  64. $> bin/behat ... You can implement step definitions for undefined

    steps with these snippets: /** * @When /^I fill in “([^”]+)” with “([^”]+)”$/ */ public function iFillInWith($val1, $val2) { throw new PendingException(); } ...
  65. $> bin/behat --append-snippets

  66. /** * @Given /^I am on homepage$/ */ public function

    iAmOnHomepage() { throw new PendingException(); } /** * @Given /^I follow “sign up”$/ */ public function iFollowSignUp() { throw new PendingException(); } /** * @When /^I fill in “([^”]+)” with “([^”]+)”$/ */ public function iFillInWith($val1, $val2) { throw new PendingException(); }
  67. $> 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 homepage TODO: write pending definition And I follow “sign up” When I fill in “email” with “linkedin@example.com” And I fill in “username” with “linkedin” And I fill in “password” with “sha1_without_salt” And I press “register” Then I should see “You have been successfully registered” And I should be on homepage 1 scenario (1 pending) 8 steps (7 skipped, 1 pending) 0m0.015s
  68. /** * @Given /^I am on homepage$/ */ public function

    iAmOnHomepage() { $crawler = new \Some\Crawler\Lib\Crawler(); $crawler->goto(“http://localhost:8080/”); if (200 !== $crawler->getCurrentStatusCode()) { throw new \RuntimeException(‘Can not open homepage’); } }
  69. $> 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 homepage Can not open homepage And I follow “sign up” When I fill in “email” with “linkedin@example.com” And I fill in “username” with “linkedin” And I fill in “password” with “sha1_without_salt” And I press “register” Then I should see “You have been successfully registered” And I should be on homepage 1 scenario (1 failed) 8 steps (7 skipped, 1 failed) 0m0.015s
  70. $> vim src/

  71. Incremental Design Implement Describe Object Narratives What do you mean

    StoryBDD TDD
  72. $> 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 homepage And I follow “sign up” TODO: write pending definition When I fill in “email” with “linkedin@example.com” And I fill in “username” with “linkedin” And I fill in “password” with “sha1_without_salt” And I press “register” Then I should see “You have been successfully registered” And I should be on homepage 1 scenario (1 pending) 8 steps (1 passed, 1 pending, 6 skipped) 0m0.015s