$30 off During Our Annual Pro Sale. View Details »

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. View Slide

  2. bdd

    View Slide

  3. View Slide

  4. It is a tool to bring
    a structure into
    agile processes.

    View Slide

  5. View Slide

  6. View Slide

  7. BDD

    View Slide

  8. BDD is agile
    enabler.

    View Slide

  9. is a BDD
    enabler

    View Slide

  10. How?

    View Slide

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

    View Slide

  12. Most of the cost
    in software
    development is in
    feedback delay

    View Slide

  13. Let’s reduce
    feedback delay

    View Slide

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

    View Slide

  15. Let’s rename a
    few things

    View Slide

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

    View Slide

  17. Incremental
    Design
    Implement
    Describe
    Object
    Narratives
    What do you
    mean
    StoryBDD
    TDD

    View Slide

  18. StoryBDD

    View Slide

  19. StoryBDD could look like functional
    TDD to people from outside BDD
    community, but it’s a lie.

    View Slide

  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.

    View Slide

  21. Some applications could easily fullfill
    developers expectations and still not
    being able to cover business needs.

    View Slide

  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.

    View Slide

  23. Exploration
    OF Domain area

    View Slide

  24. 3 levels
    of domain
    exploration

    View Slide

  25. 1
    2
    3
    narrative
    possible scenarios
    scenario details

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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
    =>

    View Slide

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

    View Slide

  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

    View Slide

  33. How?

    View Slide

  34. by Forcing you
    business
    questions
    to answer

    View Slide

  35. 1. For who?

    View Slide

  36. 1. For who?
    2. What?

    View Slide

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

    View Slide

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

    View Slide

  39. example
    Registration

    View Slide


  40. I want visitors to be able to register
    on my website through simple
    registration form.
    Your hypothetical client

    View Slide

  41. 1.Who?

    View Slide

  42. 1.Who?
    users?

    View Slide

  43. 1.Who?
    users visitors

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  47. Know
    your client
    clients!

    View Slide

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

    View Slide

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

    View Slide

  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)

    View Slide

  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)

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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: ...

    View Slide

  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: ...

    View Slide

  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 “[email protected]
    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

    View Slide

  59. View Slide

  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

    View Slide

  61. $> bin/behat --init
    +d features
    +d features/bootstrap
    +f features/bootstrap/FeatureContext.php

    View Slide

  62. 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
    }
    }

    View Slide

  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();
    }
    ...

    View Slide

  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();
    }
    ...

    View Slide

  65. $> bin/behat --append-snippets

    View Slide

  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();
    }

    View Slide

  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 “[email protected]
    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

    View Slide

  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’);
    }
    }

    View Slide

  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 “[email protected]
    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

    View Slide

  70. $> vim src/

    View Slide

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

    View Slide

  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 “[email protected]
    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

    View Slide