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.
26. StoryBDD looks like a functional
TDD to the people from the outside
of the BDD community, but
it’s a simple confusion.
27. 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.
28. Some applications could easily fulfil
developers expectations and still not being
able to cover business needs.
29. 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.
39. Feature: Authorisation
In order to get access to the shopping history
As a frequent buyer
I need to be able to authenticate
1
2
3scenario details
Scenario: Successfully authenticating
with correct credentials
40. Feature: Authorisation
In order to get access to the shopping history
As a frequent buyer
I need to be able to authenticate
1
2
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”
!
41. Feature: Authorisation
In order to get access to the shopping history
As a frequent buyer
I need to be able to authenticate
1
2
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”
!
51. Feature: Authorisation
In order to get access to the shopping history
As a frequent buyer
I need to be able to authenticate
benefit
beneficiar
52. 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
53. SELECT f.* as sprint
FROM ‘/features’ as f
ORDER BY f.role, f.benefit
LIMIT 10
PSEUDOAgileQL
54. 2. What do you
mean?
aka: defining done through examples
57. 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”
!
58. 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
59. 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)
60. 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
61. 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
62. 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”
!
63. 3. When are we
done?
aka: closing feedback loop
66. 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`
68. 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();
}
...
70. 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
74. Making it fail
/**
* @Given /^I am on the homepage$/
*/
public function iAmOnTheHomepage()
{
$crawler = new SomeCrawlerLibCrawler();
$crawler->goto(“http://localhost:8080/”);
if (200 !== $crawler->getCurrentStatusCode())
{
throw new RuntimeException(‘Can not open homepage’);
}
}
75. 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
78. 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
79. 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
80. 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
81. 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