Sunteți pe pagina 1din 83

How to make

BDD
your clients happy
using
who
AM i

@everzet senior from-birth web


developer in
who
AM i

Agile mentor in KnpLabs since 2011


http://github.com/everzet
BDD evangelist
http://card.everzet.com
Creator of Behat, Mink everzet@knplabs.com
Contributor to Symfony2 framework

@everzet senior from-birth web


developer in
Whats our
primary job ?
to make
our clients happy !
Current state:
more
awesome
languages
more
awesome
frameworks
more
awesome
developers

http://www.flickr.com/photos/officialgdc/4421337520
= clients
happiness ?
clients
happiness = valuable
product
awesome


languages
valuable
product
awesome


languages
valuable
frameworks product
awesome


languages
valuable
frameworks product
developers
awesome
valuable
valuable
product =
=
popular
valuable
product
=
popular
valuable
product useful
=
popular
valuable
product useful

profitable
BUT
?
How
to bring
value
into
client
product
especially,
when client
doesnt know that
he needs it
By asking
http://www.flickr.com/photos/brendio/71252025
Client wants
internationalization?
http://www.flickr.com/photos/editor/6698208975
Client wants
authorization?
http://www.flickr.com/photos/quinnanya/3588989219
Client wants
this new shiny
awesome feature?
Well, you got it....
CAT I O NS
MMU N I
CO

photo by joshfassbind.com
How does it helps?
Correct answers to

WHY?
helps you to bring
higher priority on
things, that really
matter
How does the correct

WHY?
answer looks like?
Correct WHY? answer
should point out:
Correct WHY? answer
should point out:

Added value of the feature


Correct WHY? answer
should point out:

Added value of the feature


Benefitiar of the feature
In order to see top users
In order to see top users
As a visitor
In order to see top users
As a visitor
I need to be able to sort them by rating
In order to see top users
As a visitor
I need to be able to sort them by rating
In order to see top users
As a visitor
I need to be able to sort them by rating

In order to get latest news


As a visitor
I need to be able to see last 3 articles on homepage
In order to see top users
As a visitor
I need to be able to sort them by rating

In order to get latest news


As a visitor
I need to be able to see last 3 articles on homepage

In order to spend my money


As a user
I need to be able to buy rating on site
of BDD

In order to [X]
As a [Y]
Its strength is that it forces you to
identify the value of delivering a
story when you first define it.

I need [Z] Dan North

X - the benefit or value of the feature


Y - the person (or role) who will benefit
Z - some feature
In order to see top users
As a visitor
I need to be able to sort them by rating

In order to get latest news


As a visitor
I need to be able to see last 3 articles on homepage

In order to spend my money


As a user
I need to be able to buy rating on site
define priorities

In order to see top users


2 As a visitor
I need to be able to sort them by rating

1
In order to get latest news
As a visitor
I need to be able to see last 3 articles on homepage

3
In order to spend my money
As a user
I need to be able to buy rating on site
In order to [X]
As a [Y]
I need [Z]
Hey, it looks like a
user story!
UserStory:
In order to [X]
As a [Y]
I need [Z]

it IS
UserStory:
In order to [X]
As a [Y]
I need [Z]

Given some initial context (the givens),


When an event occurs,
Then ensure some outcomes.
UserStory:
In order to [X]
As a [Y]
I need [Z]

Given some initial context (the givens),


When an event occurs,
Then ensure some outcomes.

Given some initial context (the givens),


When an event occurs,
Then ensure some outcomes.
UserStory:
In order to [X]
As a [Y]
I need [Z]

Scenario 1:
Given some initial context (the givens),
When an event occurs,
Then ensure some outcomes.

Scenario 2:
Given some initial context (the givens),
When an event occurs,
Then ensure some outcomes.
A storys behaviour
is simply its
acceptance criteria!
- if the system fulfills all the acceptance
criteria, its behaving correctly; if it
doesnt, it isnt.
Acceptance criteria
could be automated!
Feature: Feature description
In order to ...
As a ...
I need ...

Scenario: 1st scenario title


Given some initial context (the givens)
When an event occurs
Then ensure some outcomes

Scenario: 2nd scenario title


Given some initial context (the givens)
When an event occurs
Then ensure some outcomes
feature tree
Feature: Feature description 1. feature
In order to ...
As a ...
I need ...

Scenario: 1st scenario title


2. scenario

Given some initial context (the givens) 3. step


When an event occurs ...
Then ensure some outcomes ...

Scenario: 2nd scenario title


2. scenario

Given some initial context (the givens) 3. step


When an event occurs ...
Then ensure some outcomes ...
Given I have a bank account
<?php

$steps->Given('/^I have a bank account$/',


function($world) {
$world->account = new BankAccount();
}
);
Given I have a bank account
<?php

$steps->Given('/^I have a bank account$/',


function($world) {
$world->account = new BankAccount();
}
);

When I deposit 35$


<?php

$steps->When('/^I deposit (\d+)\$$/',


function($world, $dollars) {
$world->account->deposit($dollars);
}
);
Then I should have 35$
Then I should have 35$
<?php

$steps->Then('/^I should have (\d+)\$$/',


function($world, $balance) {
if ($balance !== $world->account->getBalance()) {
throw new \Exception('Wrong balance!');
}
}
);
<?php

$steps->Given('/^I have a bank account$/',


function($world) {
$world->account = new BankAccount();
}
);

$steps->When('/^I deposit (\d+)\$$/',


function($world, $dollars) {
$world->account->deposit($dollars);
}
);

$steps->Then('/^I should have (\d+)\$$/',


function($world, $balance) {
assertEquals($balance, $world->account->getBalance());
}
);
Feature: User logins
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Scenario: Existing user can login


Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Scenario: Existing user can login

Scenario: Non-existing user cant login


Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Scenario: Existing user can login


Given a site have everzet user with qwerty password
And I am on the /login
When I fill in username with everzet
And I fill in password with qwerty
And I press login in login form
Then I should see Welcome, everzet

Scenario: Non-existing user cant login


Given a site have everzet user with qwerty password
And I am on the /login
When I fill in username with someone
And I fill in password with qwerty
And I press login in login form
Then I should see Login or password is incorrect
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Scenario: Existing user can login


Given a site have everzet user with qwerty password
And I am on the /login
When I fill in username with everzet
And I fill in password with qwerty
And I press login in login form
Then I should see Welcome, everzet

Scenario: Non-existing user cant login


Given a site have everzet user with qwerty password
And I am on the /login
When I fill in username with someone
And I fill in password with qwerty
And I press login in login form
Then I should see Login or password is incorrect
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Scenario: Existing user can login


Given I am on the /login page
When I fill in username with everzet
And I fill in password with qwerty
And I press login in login form
Then I should see Welcome, everzet

Scenario: Non-existing user cant login


Given I am on the /login page
When I fill in username with someone
And I fill in password with qwerty
And I press login in login form
Then I should see Login or password is incorrect
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Background:
Given a site have everzet user with qwerty password

Scenario: Existing user can login


Given I am on the /login page
When I fill in username with everzet
And I fill in password with qwerty
And I press login in login form
Then I should see Welcome, everzet

Scenario: Non-existing user cant login


Given I am on the /login page
When I fill in username with someone
And I fill in password with qwerty
And I press login in login form
Then I should see Login or password is incorrect
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Background:
Given a site have users:
| username | password |
| everzet | qwerty |

Scenario: Existing user can login


Given I am on the /login page
When I fill in username with everzet
And I fill in password with qwerty
And I press login in login form
Then I should see Welcome, everzet

Scenario: Non-existing user cant login


Given I am on the /login page
When I fill in username with someone
And I fill in password with qwerty
And I press login in login form
Then I should see Login or password is incorrect
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Background:
Given a site have users:
| username | password |
| everzet | qwerty |

Scenario Outline: Only existing users can login


Given I am on the /login page
When I fill in username with <username>
And I fill in password with <password>
And I press login in login form
Then I should see <message>
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Background:
Given a site have users:
| username | password |
| everzet | qwerty |

Scenario Outline: Only existing users can login


Given I am on the /login page
When I fill in username with <username>
And I fill in password with <password>
And I press login in login form
Then I should see <message>

Examples:
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Background:
Given a site have users:
| username | password |
| everzet | qwerty |

Scenario Outline: Only existing users can login


Given I am on the /login page
When I fill in username with <username>
And I fill in password with <password>
And I press login in login form
Then I should see <message>

Examples:
| username | password | message |
| everzet | qwerty | Welcome, everzet |
| someone | pa$$word | Login or password is incorrect |
In-browser testing and
frameworks support
Sahi
Goutte
Selenium
sfBrowser
Symfony2 Client
Sahi
Goutte
Selenium
sfBrowser
Symfony2 Client

through one clean API


M!"#
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Background:
Given a site have users:
| username | password |
| everzet | qwerty |

Scenario Outline: Only existing users can login


Given I am on the /login page
When I fill in username with <username>
And I fill in password with <password>
And I press login in login form
Then I should see <message>

Examples:
| username | password | message |
| everzet | qwerty | Welcome, everzet |
| someone | pa$$word | Login or password is incorrect |
Feature: User logins
In order to have extended abilities
As a site user
I need to be able to login

Background:
Given a site have users:
| username | password |
| everzet | qwerty |

@javascript
Scenario Outline: Only existing users can login
Given I am on the /login page
When I fill in username with <username>
And I fill in password with <password>
And I press login in login form
Then I should see <message>

Examples:
| username | password | message |
| everzet | qwerty | Welcome, everzet |
| someone | pa$$word | Login or password is incorrect |
Questions?

S-ar putea să vă placă și