Enabling agile devliery through enabling BDD in PHP projects

Preview:

DESCRIPTION

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.

Citation preview

Enabling AgileThrough enabling BDD in PHP projects

Who?BDD Evangelist

!Creator of Behat, Mink, PhpSpec2,

Prophecy !

Contributor to Symfony2, Composer !

Host of the “Elephant in the Room” podcast

BDD

– me, this month

BDD is a tool to bring structure into the agile processes

Agile processOut-of-the box

Agile processOut-of-the box

BDDIn the Agile process

BDD is the agile enabler

How does it enable Agile?

Requirements

Analysis

Design

Development

Testing

9 months 3 m 2 m 12 m ...

[Royce 1970]

Most of the cost in software development is

in the feedback delay

Lets reduce feedback delay

Requirements

Acceptance

Testing

Coding

Refactoring

Weeks Minutes

[Beck & Cunningham 1996-99]

Requirements

Acceptance

Testing?

Coding

Refactoring

[North 2003]

Weeks Minutes

Lets clarify design intentions

Requirements

Acceptance

Specification

Implementation

Refactoring

[North 2003]

Weeks Minutes

Lets clarify planning intentions

Adding value

What do you mean?

Specification

Implementation

Refactoring

[North 2003]

Weeks Minutes

Adding value

What do you mean?

Specification

Implementation

Refactoring

[North 2003]

Adding value

What do you mean?

Specification

Implementation

Refactoring

[North 2003]

StoryBDD

SpecBDD

[North 2003]

Adding value

What do you mean?

Specification

Implementation

Refactoring

Behat

PhpSpec

[North 2003]

Adding value

What do you mean?

Specification

Implementation

Refactoring

StoryBDD

StoryBDD looks like a functional TDD to the people from the outside

of the BDD community, but it’s a simple confusion.

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.

Some applications could easily fulfil developers expectations and still not being

able to cover business needs.

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.

User-story• Narrative

• Business rules

• Communication

• Acceptance criteria

User-story• Narrative

• Business rules == AC

• Communication

User-story• Narrative

• Business rules == AC

• Comm == Examples

User-story• Narrative

• Business rules

• Comm == Examples == AC

StoryBDD splits every feature in your project

into the 3 separate layers.

Each new layer adds more information to the

table.

12

3

narrativepossible scenarios

scenario details

12

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

Feature: Authorisation

In order to get access to the shopping history As a frequent buyer I need to be able to authenticate

12

3scenario details

Scenario: Successfully authenticating with correct credentials

Feature: Authorisation

In order to get access to the shopping history As a frequent buyer I need to be able to authenticate

12

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” !

Feature: Authorisation

In order to get access to the shopping history As a frequent buyer I need to be able to authenticate

12

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” !

StructureIn the Agile process

StoryBDD forces you to answer questions you did

not know you need to ask.

1. Why?aka: how to prioritise

my backlog

Feature: Authorisation

Why might your users want this feature?

Feature: Authorisation

In order to get access to the shopping history

Feature: Authorisation

In order to get access to the shopping history

Who is mostly interested in this

feature?

Feature: Authorisation

In order to get access to the shopping history As a frequent buyer

Feature: Authorisation

In order to get access to the shopping history As a frequent buyer

How can you help him get this value?

Feature: Authorisation

In order to get access to the shopping history As a frequent buyer I need to be able to authenticate

Feature: Authorisation

In order to get access to the shopping history As a frequent buyer I need to be able to authenticate

benefit beneficiar

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

SELECT f.* as sprint FROM ‘/features’ as f ORDER BY f.role, f.benefit LIMIT 10P

SEU

DO

Agi

leQ

L

2. What do you mean?

aka: defining done through examples

How much “done” is “done”?

How much of the feature should be

delivered?

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” !

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

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)

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

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

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” !

3. When are we done?

aka: closing feedback loop

assertEquals(Your Feature, Your App)

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`

Context<?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 { }

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

...

Append snippets$> bin/behat --append-snippets

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

Stories

Examples

Describe

ImplementDesign

Stories

Examples

Describe

ImplementDesign

Colour it red.

Making it fail /** * @Given /^I am on the homepage$/ */ public function iAmOnTheHomepage() { $crawler = new \Some\Crawler\Lib\Crawler(); $crawler->goto(“http://localhost:8080/”); if (200 !== $crawler->getCurrentStatusCode()) { throw new RuntimeException(‘Can not open homepage’); } }

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

Stories

Examples

Describe

ImplementDesign

Change the messageAs quickly as you can

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

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

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

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

Read more at behat.org

Stories

Examples

Describe

ImplementDesign

Spec-BDD

Stories

Examples

Describe

ImplementDesign

Spec-BDD

Stories

Examples

Describe

ImplementDesign

Spec-BDD

Stories

Examples

Describe

ImplementDesign

Read more at phpspec.net

That’s all nice theoretical stuff

http://inviqa.com/careers

Thank you!

Recommended