or Drupal, Behaviour Driven Development and Behat - DrupalCamp ...

motherlamentationInternet και Εφαρμογές Web

7 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

91 εμφανίσεις

zip-BDD-do-dah,
zip-BDD-ay!
or
Drupal, Behaviour Driven Development and Behat
Hello!
Behaviour Driven
Development
“BDD is a second-generation,
outside–in, pull-based, multiple-
stakeholder, multiple-scale, high-
automation, agile methodology.”
What Problem Are We Trying to Solve?
What Problem Are We Trying to Solve?
Language
What Problem Are We Trying to Solve?
Language
Assumption that when something is stated
everyone understands
What Problem Are We Trying to Solve?
Language
Assumption that when something is stated
everyone understands
Consquences: Late, delayed products
Why not (just) Test-Driven Development?
Traditional TDD - ‘Unit’ Tests
Inside Out
“Refactoring Problem” - Change code, maintain
behaviour
“Accessibility Problem” - Who can read it?
BDD
Test-Driven Development
tests written first
repeatable, automated
BDD
Test-Driven Development
tests written first
repeatable, automated
Domain Driven Design
describes the business domain
gives us a common (ubiquitous) language
BDD
Test-Driven Development
tests written first
repeatable, automated
Domain Driven Design
describes the business domain
gives us a common (ubiquitous) language
Support
Gherkin, Behat
Jenkins, JIRA, Sauce, others
BDD
The conversation...
The conversation...
Different approaches to solving problems
Variety of experiences
Understanding of jargon, motivations
Given

some context
When
do something
Then
I expect something to happen
to add business value
The scenario...
Given

I am on the gateway page
When
I login as Fred Smith
Then
I expect to be on Fred
Smith’s user account page
The scenario...
Given

I am on the gateway page
When
I login as Fred Smith
Then
I expect to be on Fred Smith’s user account page
But wait...
It’s a specification...
It’s documentation...
It’s an automated test...
“BDD is a second-generation,
outside–in, pull-based, multiple-
stakeholder, multiple-scale, high-
automation, agile methodology.”
Setup
Drupal BDD = Behat / Mink / Gherkin
+ Integration
+ Automation
Dependencies
PHP 5.3
Installation
{
"require": {
"behat/behat": "2.4.*@stable",
"behat/mink": "1.4@stable",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium-driver": "*",
"behat/mink-selenium2-driver": "*",
"behat/mink-sahi-driver": "*",
"behat/mink-zombie-driver": "*",
"drupal/drupal-extension": "*",
"symfony/process": "*",
"behat/symfony2-extension": "*",
"symfony/form": "*",
"symfony/validator": "*",
"behat/mink-extension": "*",
"symfony/http-kernel": "*",
"fabpot/goutte": "dev-master#5f7fd00",
"sauce/connect": "*",
"sauce/sausage": "*",
"vipsoft/jira-extension": "*"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin/"
}
}
Composer.json
https://packagist.org
$ curl
http://getcomposer.org/installer
| php
$ php composer.phar install
$ bin/behat --init
class FeatureContext extends DrupalContext {
...
}
http://drupal.org/project/
drupalextension
Behat.yml
# Behat.yml
default
:

paths
:

features
:

'features'

bootstrap
:

'features/bootstrap'

context
:

parameters
:

drupal_users
:

admin

user
:

username
:

'admin'

password
:

'admin'

default_browser
:

'goutte'

extensions
:
Behat\MinkExtension\Extension:

goutte
:
~

selenium2
:
~

base_url
:

'
http://londonkickstart.local
'

javascript_session
:

'selenium2'
Drupal\DrupalExtension\Extension:

drush
:

alias
:

'kickstart'
http://mink.behat.org/
#different-browsers-drivers

parameters
:

default_browser
:

'goutte'

extensions
:
Behat\MinkExtension\Extension
:
goutte
:
~

selenium2
:
~

base_url
:

'
http://londonkickstart.local
'

javascript_session
:

'selenium2'

Writing features
http://docs.behat.org/guides/1.gherkin.html
@todrink @cart
Feature:
Add drinking item to cart
In order to buy something to drink with
As any user
I should be able to add a coffee mug to my cart

Scenario:
View the drinking options text and links on the page

Given
I am on the homepage

When
I follow "To drink with"

Then
I should see the heading "Coffee Mugs"

And
I should see the link "Drupal Commerce to Wake You Up"

Scenario:
View coffee mug product information

When
I go to "/drinks/drupal-commerce-wake-you"

Then
I should see the following
<texts>

|
texts
|

|
Drupal Commerce to Wake You Up
|

|
Acme gear
|

|
$8.00
|

|
Product Description
|

|
SKU: MG1-BLU-OS
|
...
todrink.feature
Executing your features
http://docs.behat.org/guides/6.cli.html
Live Demo....
Integration
http://extensions.behat.org/jira-extension
# sauce.yml
default
:

extensions
:
Behat\MinkExtension\Extension
:

wd_host
:
SAUCE_USERNAME:API_KEY:
@ondemand.saucelabs.com
/wd/hub

default_session
:

'selenium2'
iPad
:

extensions
:
Behat\MinkExtension\Extension
:

selenium2
:

browser
:
iPad

capabilities
:

{

platform
:
Mac
10.8
,

version
:

6
}
Sauce connect = https://saucelabs.com/docs/connect
https://saucelabs.com/docs/browsers
Continuous Integration
https://github.com/tayzlor/drupal-kickstart-behat
https://saucelabs.com/u/gtayzlor
Image Credits:
http://knowyourmeme.com/photos/275025-wat
http://www.flickr.com/photos/mgifford/7396924736/
http://www.businessinfest.info/wp-content/uploads/2012/08/business-analyst.jpg
http://www.flickr.com/photos/ceardach/4550836301/
http://devopsreactions.tumblr.com/post/41776196984/first-test
https://saucelabs.com/images/sauce-labs-logo.png
http://www.atlassian.com/dms/wac/images/press/Atlassian-logos/logoPNG.zip
https://wiki.jenkins-ci.org/download/attachments/2916393/logo-title.png?version=1&modificationDate=1302753947000
http://static.domenkozar.com/slides/travis.png
http://www.atlassian.com/dms/wac/images/press/Atlassian-logos/logoPNG.zip
http://4.bp.blogspot.com/-_dN0F-9n76s/TwSPAUgj1zI/AAAAAAAAAyQ/8isCGE2Idnk/s1600/gherkin.jpeg
Thank You!
We are
Graham Taylor @g_taylor
Andrew Larcombe @andrewl
Links
Dan North:
http://dannorth.net/blog
Liz Keogh:
http://lizkeogh.com
Gojko Adzic:
http://gojko.net
http://specificationbyexample.com
Behat - http://behat.org
Mink - http://mink.behat.org
http://drupal.org/project/doobie