enabling agile devliery through enabling bdd in php projects

91
Enabling Agile Through enabling BDD in PHP projects

Upload: konstantin-kudryashov

Post on 08-May-2015

1.776 views

Category:

Technology


0 download

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.

TRANSCRIPT

Page 1: Enabling agile devliery through enabling BDD in PHP projects

Enabling AgileThrough enabling BDD in PHP projects

Page 2: Enabling agile devliery through 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

Page 3: Enabling agile devliery through enabling BDD in PHP projects
Page 4: Enabling agile devliery through enabling BDD in PHP projects
Page 5: Enabling agile devliery through enabling BDD in PHP projects

BDD

Page 6: Enabling agile devliery through enabling BDD in PHP projects

– me, this month

BDD is a tool to bring structure into the agile processes

Page 7: Enabling agile devliery through enabling BDD in PHP projects

Agile processOut-of-the box

Page 8: Enabling agile devliery through enabling BDD in PHP projects

Agile processOut-of-the box

Page 9: Enabling agile devliery through enabling BDD in PHP projects

BDDIn the Agile process

Page 10: Enabling agile devliery through enabling BDD in PHP projects

BDD is the agile enabler

Page 11: Enabling agile devliery through enabling BDD in PHP projects

How does it enable Agile?

Page 12: Enabling agile devliery through enabling BDD in PHP projects

Requirements

Analysis

Design

Development

Testing

9 months 3 m 2 m 12 m ...

[Royce 1970]

Page 13: Enabling agile devliery through enabling BDD in PHP projects

Most of the cost in software development is

in the feedback delay

Page 14: Enabling agile devliery through enabling BDD in PHP projects

Lets reduce feedback delay

Page 15: Enabling agile devliery through enabling BDD in PHP projects

Requirements

Acceptance

Testing

Coding

Refactoring

Weeks Minutes

[Beck & Cunningham 1996-99]

Page 16: Enabling agile devliery through enabling BDD in PHP projects

Requirements

Acceptance

Testing?

Coding

Refactoring

[North 2003]

Weeks Minutes

Page 17: Enabling agile devliery through enabling BDD in PHP projects

Lets clarify design intentions

Page 18: Enabling agile devliery through enabling BDD in PHP projects

Requirements

Acceptance

Specification

Implementation

Refactoring

[North 2003]

Weeks Minutes

Page 19: Enabling agile devliery through enabling BDD in PHP projects

Lets clarify planning intentions

Page 20: Enabling agile devliery through enabling BDD in PHP projects

Adding value

What do you mean?

Specification

Implementation

Refactoring

[North 2003]

Weeks Minutes

Page 21: Enabling agile devliery through enabling BDD in PHP projects

Adding value

What do you mean?

Specification

Implementation

Refactoring

[North 2003]

Page 22: Enabling agile devliery through enabling BDD in PHP projects

Adding value

What do you mean?

Specification

Implementation

Refactoring

[North 2003]

Page 23: Enabling agile devliery through enabling BDD in PHP projects

StoryBDD

SpecBDD

[North 2003]

Adding value

What do you mean?

Specification

Implementation

Refactoring

Page 24: Enabling agile devliery through enabling BDD in PHP projects

Behat

PhpSpec

[North 2003]

Adding value

What do you mean?

Specification

Implementation

Refactoring

Page 25: Enabling agile devliery through enabling BDD in PHP projects

StoryBDD

Page 26: Enabling agile devliery through enabling BDD in PHP projects

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

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

Page 27: Enabling agile devliery through enabling BDD in PHP projects

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.

Page 28: Enabling agile devliery through enabling BDD in PHP projects

Some applications could easily fulfil developers expectations and still not being

able to cover business needs.

Page 29: Enabling agile devliery through enabling BDD in PHP projects

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.

Page 30: Enabling agile devliery through enabling BDD in PHP projects
Page 31: Enabling agile devliery through enabling BDD in PHP projects

User-story• Narrative

• Business rules

• Communication

• Acceptance criteria

Page 32: Enabling agile devliery through enabling BDD in PHP projects

User-story• Narrative

• Business rules == AC

• Communication

Page 33: Enabling agile devliery through enabling BDD in PHP projects

User-story• Narrative

• Business rules == AC

• Comm == Examples

Page 34: Enabling agile devliery through enabling BDD in PHP projects

User-story• Narrative

• Business rules

• Comm == Examples == AC

Page 35: Enabling agile devliery through enabling BDD in PHP projects

StoryBDD splits every feature in your project

into the 3 separate layers.

Page 36: Enabling agile devliery through enabling BDD in PHP projects

Each new layer adds more information to the

table.

Page 37: Enabling agile devliery through enabling BDD in PHP projects

12

3

narrativepossible scenarios

scenario details

Page 38: Enabling agile devliery through enabling BDD in PHP projects

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

Page 39: Enabling agile devliery through enabling BDD in PHP projects

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

Page 40: Enabling agile devliery through enabling BDD in PHP projects

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

Page 41: Enabling agile devliery through enabling BDD in PHP projects

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

Page 42: Enabling agile devliery through enabling BDD in PHP projects

StructureIn the Agile process

Page 43: Enabling agile devliery through enabling BDD in PHP projects

StoryBDD forces you to answer questions you did

not know you need to ask.

Page 44: Enabling agile devliery through enabling BDD in PHP projects

1. Why?aka: how to prioritise

my backlog

Page 45: Enabling agile devliery through enabling BDD in PHP projects

Feature: Authorisation

Why might your users want this feature?

Page 46: Enabling agile devliery through enabling BDD in PHP projects

Feature: Authorisation

In order to get access to the shopping history

Page 47: Enabling agile devliery through enabling BDD in PHP projects

Feature: Authorisation

In order to get access to the shopping history

Who is mostly interested in this

feature?

Page 48: Enabling agile devliery through enabling BDD in PHP projects

Feature: Authorisation

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

Page 49: Enabling agile devliery through enabling BDD in PHP projects

Feature: Authorisation

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

How can you help him get this value?

Page 50: Enabling agile devliery through enabling BDD in PHP projects

Feature: Authorisation

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

Page 51: Enabling agile devliery through enabling BDD in PHP projects

Feature: Authorisation

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

benefit beneficiar

Page 52: Enabling agile devliery through enabling BDD in PHP projects

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

Page 53: Enabling agile devliery through enabling BDD in PHP projects

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

SEU

DO

Agi

leQ

L

Page 54: Enabling agile devliery through enabling BDD in PHP projects

2. What do you mean?

aka: defining done through examples

Page 55: Enabling agile devliery through enabling BDD in PHP projects

How much “done” is “done”?

Page 56: Enabling agile devliery through enabling BDD in PHP projects

How much of the feature should be

delivered?

Page 57: Enabling agile devliery through enabling BDD in PHP projects

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

Page 58: Enabling agile devliery through enabling BDD in PHP projects

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

Page 59: Enabling agile devliery through enabling BDD in PHP projects

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)

Page 60: Enabling agile devliery through enabling BDD in PHP projects

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

Page 61: Enabling agile devliery through enabling BDD in PHP projects

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

Page 62: Enabling agile devliery through enabling BDD in PHP projects

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

Page 63: Enabling agile devliery through enabling BDD in PHP projects

3. When are we done?

aka: closing feedback loop

Page 64: Enabling agile devliery through enabling BDD in PHP projects
Page 65: Enabling agile devliery through enabling BDD in PHP projects

assertEquals(Your Feature, Your App)

Page 66: Enabling agile devliery through enabling BDD in PHP projects

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`

Page 67: Enabling agile devliery through enabling BDD in PHP projects

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

Page 68: Enabling agile devliery through enabling BDD in PHP projects

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

...

Page 69: Enabling agile devliery through enabling BDD in PHP projects

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

Page 70: Enabling agile devliery through enabling BDD in PHP projects

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

Page 71: Enabling agile devliery through enabling BDD in PHP projects

Stories

Examples

Describe

ImplementDesign

Page 72: Enabling agile devliery through enabling BDD in PHP projects

Stories

Examples

Describe

ImplementDesign

Page 73: Enabling agile devliery through enabling BDD in PHP projects

Colour it red.

Page 74: Enabling agile devliery through enabling BDD in PHP projects

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

Page 75: Enabling agile devliery through enabling BDD in PHP projects

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

Page 76: Enabling agile devliery through enabling BDD in PHP projects

Stories

Examples

Describe

ImplementDesign

Page 77: Enabling agile devliery through enabling BDD in PHP projects

Change the messageAs quickly as you can

Page 78: Enabling agile devliery through enabling BDD in PHP projects

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

Page 79: Enabling agile devliery through enabling BDD in PHP projects

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

Page 80: Enabling agile devliery through enabling BDD in PHP projects

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

Page 81: Enabling agile devliery through enabling BDD in PHP projects

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

Page 82: Enabling agile devliery through enabling BDD in PHP projects

Read more at behat.org

Page 83: Enabling agile devliery through enabling BDD in PHP projects

Stories

Examples

Describe

ImplementDesign

Spec-BDD

Page 84: Enabling agile devliery through enabling BDD in PHP projects

Stories

Examples

Describe

ImplementDesign

Spec-BDD

Page 85: Enabling agile devliery through enabling BDD in PHP projects

Stories

Examples

Describe

ImplementDesign

Spec-BDD

Page 86: Enabling agile devliery through enabling BDD in PHP projects

Stories

Examples

Describe

ImplementDesign

Page 87: Enabling agile devliery through enabling BDD in PHP projects

Read more at phpspec.net

Page 88: Enabling agile devliery through enabling BDD in PHP projects

That’s all nice theoretical stuff

Page 89: Enabling agile devliery through enabling BDD in PHP projects
Page 90: Enabling agile devliery through enabling BDD in PHP projects

http://inviqa.com/careers

Page 91: Enabling agile devliery through enabling BDD in PHP projects

Thank you!