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

T3CON13: Web application development using Behaviour Driven Development

T3CON13: Web application development using Behaviour Driven Development

License: CC BY-SA

While Test-Driven Development (TDD) has already emerged as a widely accepted standard in agile software development over the past decade, the relatively young concept of Behaviour-Driven Development (BDD) tries to apply TDD principles to bridge the gap between developers and domain experts.

This talk aims at illustrating the basic principles of Behaviour Driven Development and will introduce appropriate tools that can be used for automated acceptance testing of web applications, like Cucumber, Behat and Mink.

The talk will include some real-life examples from Mittwald’s software development department. It will discuss the costs and benefits of BDD and how BDD can improve your software quality and ease both the developer’s and product owner’s mind.

Martin Helmich

October 30, 2013
Tweet

More Decks by Martin Helmich

Other Decks in Programming

Transcript

  1. Speed

    View Slide

  2. YOUR

    View Slide

  3. Show

    View Slide

  4. Franck

    View Slide

  5. Requirements

    View Slide

  6. Requirements

    View Slide

  7. Each

    View Slide

  8. Product

    View Slide

  9. Product
    Owner
    Development
    Team
    Product
    Backlog
    writes
    stories
    Sprint
    Backlog
    Selected
    by

    View Slide

  10. Another
    (also

    View Slide

  11. Failing
    test
    Passing
    test
    Refactor
    Test-Driven

    View Slide

  12. Unit

    View Slide

  13. Unit

    View Slide

  14. Acceptance

    View Slide

  15. Acceptance

    View Slide

  16. Acceptance

    View Slide

  17. Introducing
    Gherkin
    CC

    View Slide

  18. Gherkin

    View Slide

  19. Acceptance

    View Slide

  20. Acceptance

    View Slide

  21. class MyTest extends PHPUnit_Extensions_Selenium2TestCase
    {
    protected function setUp()
    {
    $this->setBrowser('*firefox');
    $this->setBrowserUrl('http://login.mittwald.de/');
    }
    public function testLoginWithCorrectCredentialsWorksCorrectly()
    {
    $this->url('login.html');
    $this->byXPath('//input[@id="login_username"]')->value('123456');
    $this->byXPath('//input[@id="login_password"]')->value('supersecret');
    $this
    ->byXPath('//input[@type="submit" and @name="login_password"]')
    ->clickAndWait();
    $this->frame(0);
    $this->assertContains(
    'Welcome to the customer center',
    $this->byXPath('//body')->text()
    );
    }
    }
    ?>
    Scenario: User login
    Given I am on "login.mittwald.de"
    When I fill in "123456" for "username"
    And fill in "supersecret" for "password"
    And press "log in"
    Then I should see "Welcome to the customer center"
    24 6
    Lines

    View Slide

  22. Tools
    that

    View Slide

  23. Cucumber Behat
    Decym92,

    View Slide

  24. Behat Mink
    Goutte
    Driver
    Selenium
    Driver
    Web
    Driver
    Sahi
    Driver
    Zombie
    Driver
    Selenium
    Sahi
    Zombie

    View Slide

  25. Install

    View Slide

  26. You

    View Slide

  27. Scenario: Registration form
    Given I am on "index.php?id=512"
    When I follow "register now!"
    And I fill in "user_name" with "Max Mustermann"
    And I fill in "user_email" with "[email protected]"
    And I attach the file "/Users/mmustermann/max.jpeg"
    to "user_image"
    And I press "submit registration"
    Then I should be on "index.php?id=514"
    And the response should contain "Thank you ..."
    And the mailbox "m15273" should contain an email with
    subject "Your registration"

    View Slide

  28. Scenario: Registration form
    Given I am on "index.php?id=512"
    When I follow "register now!"
    And I fill in "user_name" with "Max Mustermann"
    And I fill in "user_email" with "[email protected]"
    And I attach the file "/Users/mmustermann/max.jpeg"
    to "user_image"
    And I press "submit registration"
    Then I should be on "index.php?id=514"
    And the response should contain "Thank you ..."
    And the mailbox "m15273" should contain an email with
    subject "Your registration"
    This

    View Slide

  29. Better!
    Feature: Online registration
    In order to use the site's personalized features
    As an anonymous user
    I want to register to the page.
    Scenario: Registration is confirmed
    Given I am on the registration page
    And I fill in the following:
    | Full name | Max Mustermann |
    | Email address | [email protected] |
    And I upload an image of myself
    And submit the registration
    Then I should see a confirmation message
    And I should receive a confirmation email

    View Slide

  30. Feature: Online registration
    In order to use the site's personalized features
    As an anonymous user
    I want to register to the page.
    Scenario: Registration is confirmed
    Given I am on the registration page
    And I fill in the following:
    | Full name | Max Mustermann |
    | Email address | [email protected] |
    And I upload an image of myself
    And submit the registration
    Then I should see a confirmation message
    And I should receive a confirmation email
    Who

    View Slide

  31. Then /^(?:I| ) should receive a confirmation e?mail$/ do
    # Connect to mailbox and see if mail is actually there.
    # Throw exception otherwise.
    end
    class FeatureContext extends Context
    {
    /**
    * @Then /^(?:|I )should receive a confirmation e?mail$/
    */
    public function assertRegistrationMailWasReceived()
    {
    // Connect to mailbox and see if mail is actually there.
    // Throw exception otherwise.
    }
    }

    View Slide

  32. View Slide

  33. Product
    Owner
    Stories

    View Slide

  34. Integrate

    View Slide

  35. Possible

    View Slide

  36. Possible

    View Slide

  37. Possible

    View Slide

  38. Possible

    View Slide

  39. How

    View Slide

  40. BDD

    View Slide

  41. BDD

    View Slide

  42. Bogdan

    View Slide

  43. BDD

    View Slide

  44. Duncan

    View Slide

  45. References
    Gärtner,

    View Slide