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

Behaviour Driven Development

James Cowie
November 04, 2014

Behaviour Driven Development

An introduction into Agile, User stories, Cynefin framework BDD, PHPSpec and Behat

James Cowie

November 04, 2014
Tweet

More Decks by James Cowie

Other Decks in Technology

Transcript

  1. Who am I • James Cowie • Software Engineer •

    Session Digital • BDD Practitioner • @jcowie • github.com/jamescowie
  2. Introducing BDD “Software development practice that emphasises development through an

    example-based conversations with users and stakeholders of the system.“
  3. Introducing BDD “Software development practice that emphasises development through an

    example-based conversations with users and stakeholders of the system.“
  4. Evolution / Process of BDD • Inspired by eXtreme programming

    and Agile • Example workshops • User stories • Story mapping
  5. What is BDD • Evolved from Test-first development • Common

    language • Behaviour • Discovering and delivery what matters most first
  6. As a Zoologist I want to add a new animal

    to the site So that I can share my animal knowledge with the community Scenario: successful submission Given I'm on the animal creation page When I fill in Name with 'Alligator' And select Phylum as 'Chordata' And fill in Animal Class with 'Sauropsida' And check Lay Eggs And click the Create button Then I should see the notice 'Thank you for your animal submission!' And the page should include the animal's name, phylum, animal class, order, family, and
  7. As a Zoologist I want to add a new animal

    to the site So that I can share my animal knowledge with the community Scenario: successful submission Given I'm on the animal creation page When I add a new animal Then I should see the page for my newly created animal And the notice 'Thank you for your animal submission!'
  8. Given I am trying to do something When I make

    an action on it Then I expect something in return
  9. { "require-dev": { "phpspec/phpspec": "2.*", "behat/behat": "3.*" }, "autoload": {

    “psr-0": {"": "src/"} }, "config": { "bin-dir": "bin" } }
  10. Feature: I can calculate string values As a user I

    want to be able to calculate the sum of two strings. Scenario: Returns 0 when no string values are passed Given the current value to calculate is " " When I calculate the sum Then the sum value for " " is zero
  11. class FeatureContext implements Context, SnippetAcceptingContext { protected $value; /** *

    @Given the current value to calculate is :value */ public function theCurrentValueToCalculateIs($value) { $this->value = $value; }
  12. /** * @When I calculate the sum */ public function

    iCalculateTheSum() { $output = (new Acme\Calculator())->calculate($this->value); } /** * @Then the sum value for :arg1 is zero */ public function theSumValueForIsZero($arg1) { expect($this->output)->toBe(0); }
  13. Scenario: Returns 0 when no string values are passed Given

    the current value to calculate is " " When I calculate the sum Then the sum value for " " is zero --- Failed scenarios: features/feature-file.feature:5
  14. Scenario: Returns 0 when no string values are passed Given

    the current value to calculate is " " When I calculate the sum Then the sum value for " " is zero
  15. Scenario: Returns the number if only a single number is

    passed Given the current value to calculate is "1" When I calculate the sum Then the sum value for "1" is one
  16. Fail Then the sum value for "1" is one Expected

    <value>"1"</value>, but got <value>[integer:0]</value>
  17. public function calculate($number) { if ($number == " " )

    { return 0; } else { return (int)$number; } }
  18. phpspec r --format=pretty Acme\Calculator 10 ✔ is initializable 15 ✔

    should return zero when empty string is passed 20 ✔ should return the number for single number Feature: I can calculate string values As a user I want to be able to calculate the sum of two strings. Scenario: Returns 0 when no string values are passed Given the current value to calculate is " “ When I calculate the sum Then the sum value for " " is zero Scenario: Returns the number if only a single number is passed Given the current value to calculate is “1" When I calculate the sum Then the sum value for "1" is one