© Ibuildings 2014/2015 - All rights reserved
#DrupalDaysEU
Bridging the gap between business and
technology
Behavior Driven Developement with Drupal
by Marcin Pajdzik
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Gold Sponsors
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Media Sponsors
Silver Sponsors
© Ibuildings 2014/2015 - All rights reserved
#DrupalDaysEU
Bridging the gap between business and
technology
Behavior Driven Developemnt with Drupal
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
How BDD works?
Write scenarios that describe behaviours
Execute the scenarios against your application
▼
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
How BDD works?
Write each step of your scenario in plain English
Write each step definition in PHP
▼
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
NHS - National Health Service
Project started in 2002
Project terminated in 2010
Cost: €14 400 000 000
(billion)
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
NHS - National Health Service
€14.4bn would pay a salary of:
60000 nurses for 10 years in the UK
240000 nurses for 10 years in Poland
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
NHS - National Health Service
Result:
IT system was not FIT for the NHS
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Why projects fail?
3. Unrealistic deadlines.
2. Insufficient resource planning.
1. Poor communication.
Source: Computing Technology Industry Association, 2007
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Source: Project Management Institute, 2013
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Software development is about delivering BUSINESS VALUE
Business value is WHAT REALLY MATTERS to the business
We find out WHAT REALLY MATTERS to the business...
… through effective communication!
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Why communication is difficult?
Two people - misunderstandings
Technical and Business people - different type of language
Typical large IT project - large team, working in a fast-evolving
digital domain that no one fully understands
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
The main idea behind BDD
Preventing communication gaps
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
What is BDD?
Agile methodology based on Test Driven Development
Promotes communication, conversation and close collaboration
between everybody in the team
Focuses on writing specification of the system behaviour
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Benefits of BDD
3. Business and behaviour first - prioritisation
1. Collaboration / Communication - same language for all
2. Quality – functional / integration / regression tests
4. Documentation
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
BDD stories
Title (one line describing the story)
Narrative:
As a [role]
I want [feature]
So that [benefit]
Acceptance Criteria: (presented as Scenarios)
Scenario 1: Title
Given [context]
When [event]
Then [outcome]
Scenario 2: ...
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
BDD stories
As a user
I want to login
So that I can access my account
As a [X]
I want [Y]
so that [Z]
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Scenarios
Given some initial context
When an event occurs,
Then ensure some outcomes.
Given I am on the login page
When I login as “jsmith” with password “secret”
Then I should see my account page
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Scenarios
● It is a specification that everybody understands
● It is a documentation that everybody can refer to
● It is an automated test that can be run any time
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
BDD solves TDD shortcomings
Developers want to know:
●where to start
●what to test and what not to test
●how much to test in one go
●what to call their tests
●how to understand why a test fails
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Declarative Scenario vs Imperative Scenario
Given I am on the login page
When I login as “john” with password “secret”
Then I should see my account page
When I go to "user/login"
And I enter "john" into the field "username"
And I enter "secret" into the field "password"
And I click on the button "login"
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Drawbacks
Increases the cost of maintenance
Before doing BDD make sure that there is enough return on
investment to justify it.
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
BDD with Drupal
Behat - allows you to write tests in a human-readable language called
Gherkin and parses it into executable test-cases
Mink - web acceptance tests, provides MinkContext with step
definitions for interactions with a browser
Drupal Extension - provides Drupal specific functionality
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Drupal Extension Drivers
Blackbox Driver
Drupal API Driver
Drush Driver
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Drupal Extension Drivers
Blackbox Driver
Drupal API Driver
Drush Driver
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
System Requirements
PHP 5.3.5 or higher with curl, mbstring and xml
Java required for Selenium
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Installation
{
"require": {
"behat/behat": "2.4.*@stable"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin/"
}
}
$ curl http://getcomposer.org/installer | php
$ php composer.phar install
$ bin/behat
$ mkdir ls_project
$ cd ls_project
$ behat --init
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Installation
default:
paths:
features: 'features'
extensions:
BehatMinkExtensionExtension:
goutte: ~
selenium2: ~
base_url: http://seven.l
DrupalDrupalExtensionExtension:
blackbox: ~
Make your FeatureContext.php aware
of both the Drupal Extension and the
Mink Extension
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
How to make the scenarios available to everybody?
Behat Jira Extension
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Behat Jira Extension
{code:none}Feature: Jira integration
In order to facilitate the authoring of Behat features by non-developers
As a developer
I want to write an extension to load features from Jira issues.
Scenario: Load Me!
Given I am a Jira issue
And I contain a Behat feature
When I am loaded by JiraExtension
Then I should parsed by Gherkin
{code}
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
Behat Jira Extension
bin/behat jira:BDD-1
bin/behat http://jira.example.com:8080/browse/BDD-1
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
BDD in business
“After the decision to move our websites onto Drupal, adopting
Behavior Driven Development has been one of the best decisions
we’ve made for our organization in years.”
Paul Lomax - CTO, Dennis Publishing
#DrupalDaysEU
© Ibuildings 2014/2015 - All rights reserved
References
Dan North & Associates - http://dannorth.net/
Mink - http://mink.behat.org/
Behat - http://behat.org/
DSpeak - http://dspeak.com/drupalextension/intro.html
© Ibuildings 2014/2015 - All rights reserved
Speaker Info
Marcin Pajdzik
Web Technology Consultant
marcin@pajdzik.com
marcin_pajdzik
© Ibuildings 2014/2015 - All rights reserved
Bridging the gap between business and technology
Behaviour Driven Developement with Drupal

Bridging the gap between business and technology - Behaviour Driven Development with Drupal (European Drupal days 2015)

  • 1.
    © Ibuildings 2014/2015- All rights reserved #DrupalDaysEU Bridging the gap between business and technology Behavior Driven Developement with Drupal by Marcin Pajdzik
  • 2.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Gold Sponsors
  • 3.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Media Sponsors Silver Sponsors
  • 4.
    © Ibuildings 2014/2015- All rights reserved #DrupalDaysEU Bridging the gap between business and technology Behavior Driven Developemnt with Drupal
  • 5.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved How BDD works? Write scenarios that describe behaviours Execute the scenarios against your application ▼
  • 6.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved How BDD works? Write each step of your scenario in plain English Write each step definition in PHP ▼
  • 7.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved NHS - National Health Service Project started in 2002 Project terminated in 2010 Cost: €14 400 000 000 (billion)
  • 8.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved NHS - National Health Service €14.4bn would pay a salary of: 60000 nurses for 10 years in the UK 240000 nurses for 10 years in Poland
  • 9.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved NHS - National Health Service Result: IT system was not FIT for the NHS
  • 10.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Why projects fail? 3. Unrealistic deadlines. 2. Insufficient resource planning. 1. Poor communication. Source: Computing Technology Industry Association, 2007
  • 11.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Source: Project Management Institute, 2013
  • 12.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Software development is about delivering BUSINESS VALUE Business value is WHAT REALLY MATTERS to the business We find out WHAT REALLY MATTERS to the business... … through effective communication!
  • 13.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Why communication is difficult? Two people - misunderstandings Technical and Business people - different type of language Typical large IT project - large team, working in a fast-evolving digital domain that no one fully understands
  • 14.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved The main idea behind BDD Preventing communication gaps
  • 15.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved What is BDD? Agile methodology based on Test Driven Development Promotes communication, conversation and close collaboration between everybody in the team Focuses on writing specification of the system behaviour
  • 16.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Benefits of BDD 3. Business and behaviour first - prioritisation 1. Collaboration / Communication - same language for all 2. Quality – functional / integration / regression tests 4. Documentation
  • 17.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved BDD stories Title (one line describing the story) Narrative: As a [role] I want [feature] So that [benefit] Acceptance Criteria: (presented as Scenarios) Scenario 1: Title Given [context] When [event] Then [outcome] Scenario 2: ...
  • 18.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved BDD stories As a user I want to login So that I can access my account As a [X] I want [Y] so that [Z]
  • 19.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Scenarios Given some initial context When an event occurs, Then ensure some outcomes. Given I am on the login page When I login as “jsmith” with password “secret” Then I should see my account page
  • 20.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Scenarios ● It is a specification that everybody understands ● It is a documentation that everybody can refer to ● It is an automated test that can be run any time
  • 21.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved BDD solves TDD shortcomings Developers want to know: ●where to start ●what to test and what not to test ●how much to test in one go ●what to call their tests ●how to understand why a test fails
  • 22.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Declarative Scenario vs Imperative Scenario Given I am on the login page When I login as “john” with password “secret” Then I should see my account page When I go to "user/login" And I enter "john" into the field "username" And I enter "secret" into the field "password" And I click on the button "login"
  • 23.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Drawbacks Increases the cost of maintenance Before doing BDD make sure that there is enough return on investment to justify it.
  • 24.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved BDD with Drupal Behat - allows you to write tests in a human-readable language called Gherkin and parses it into executable test-cases Mink - web acceptance tests, provides MinkContext with step definitions for interactions with a browser Drupal Extension - provides Drupal specific functionality
  • 25.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Drupal Extension Drivers Blackbox Driver Drupal API Driver Drush Driver
  • 26.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Drupal Extension Drivers Blackbox Driver Drupal API Driver Drush Driver
  • 27.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved System Requirements PHP 5.3.5 or higher with curl, mbstring and xml Java required for Selenium
  • 28.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Installation { "require": { "behat/behat": "2.4.*@stable" }, "minimum-stability": "dev", "config": { "bin-dir": "bin/" } } $ curl http://getcomposer.org/installer | php $ php composer.phar install $ bin/behat $ mkdir ls_project $ cd ls_project $ behat --init
  • 29.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Installation default: paths: features: 'features' extensions: BehatMinkExtensionExtension: goutte: ~ selenium2: ~ base_url: http://seven.l DrupalDrupalExtensionExtension: blackbox: ~ Make your FeatureContext.php aware of both the Drupal Extension and the Mink Extension
  • 30.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved How to make the scenarios available to everybody? Behat Jira Extension
  • 31.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Behat Jira Extension {code:none}Feature: Jira integration In order to facilitate the authoring of Behat features by non-developers As a developer I want to write an extension to load features from Jira issues. Scenario: Load Me! Given I am a Jira issue And I contain a Behat feature When I am loaded by JiraExtension Then I should parsed by Gherkin {code}
  • 32.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved Behat Jira Extension bin/behat jira:BDD-1 bin/behat http://jira.example.com:8080/browse/BDD-1
  • 33.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved BDD in business “After the decision to move our websites onto Drupal, adopting Behavior Driven Development has been one of the best decisions we’ve made for our organization in years.” Paul Lomax - CTO, Dennis Publishing
  • 34.
    #DrupalDaysEU © Ibuildings 2014/2015- All rights reserved References Dan North & Associates - http://dannorth.net/ Mink - http://mink.behat.org/ Behat - http://behat.org/ DSpeak - http://dspeak.com/drupalextension/intro.html
  • 35.
    © Ibuildings 2014/2015- All rights reserved Speaker Info Marcin Pajdzik Web Technology Consultant marcin@pajdzik.com marcin_pajdzik
  • 36.
    © Ibuildings 2014/2015- All rights reserved Bridging the gap between business and technology Behaviour Driven Developement with Drupal