behaviour driven development

16
BDD Behaviour Driven Development Why we should use it

Upload: richard-ruiter

Post on 17-Aug-2015

95 views

Category:

Software


0 download

TRANSCRIPT

BDDBehaviour Driven Development

Why we should use it

Project restarts

One of the major causes of both cost and time overruns is restarts.

For every 100 projects that start, there are 94 restarts. This does not mean that 94 of 100 will have one restart, some projects can have several restarts.

src: http://www.projectsmart.co.uk/docs/chaos-report.pdf

What is BDD?

Behavior Driven Development (BDD) is a software engineering practice designed to help teams build and deliver more valuable, higher quality software faster.

It is not about programming, testing or management.

It's about building together.

Building together

To do this, we need a way to describe the requirement such that everyone● the business folks (customer)● the product owner● the development team

have a common understanding of the scope of the work.

source: http://dannorth.net/whats-in-a-story/

Actionable

Common understanding

Business value

Low hanging fruit

Product requirements Delivery

Impact analyses

Acceptance criteria

JavaScript

Performance

tweakers.net

Trafficker Advertisements Video ViewsWe all have our jargon….

Use case

It would be great if we could connect multiple advertisement agents worldwide. Then visitors can see local advertisements.

Feature: Local advertisements for visitors

In order to see local advertisements, As a Visitor I want the website to detect my country settings, So that the right Advertising agent will serve my advertisements

Present the story to the dev team

The Visitor doesn't benefit from this feature, but the Advertising traffickers. They will have full control over country based advertisements. How about control on channels?

Feature: Country Based Advertisement Serving on portals

In order to be able to serve advertisements by different agents As a Advertising trafficker I want define the agent based on the country and channel

Making the boss happy

I love you guys. This will bring in even more $ money $. While you're on it please add support for pages as well....

Feature: Country Based Advertisement Serving on portals

In order to be able to serve advertisements by different agents As a Advertising trafficker I want define the agent based on the country, channel and page

Writing the story

Feature: Country Based Advertisement Serving on portals

In order to be able to serve advertisements by different agents As a Advertising trafficker I want define the agent based on the country, portal and page

Refining the storyFeature: Country Based Advertisement Serving on portals

In order to be able to serve advertisements by different agents As a Advertising trafficker I want define the agent based on the country, portal and page

Scenario Outline: Visitors on certain channel pages Given the visitor is from "<country>" When the visitor is on the "<page>" page And the visitor is on the "<channel>" channel Then advertisements should be served by <agent>

Examples: ####################################################### | country | page | channel | agent | ####################################################### | default | default | default | Google | | The Netherlands | home | default | Google | | America | game | Family | AdTech | | America | home | Teens | StarMedia | | America | home | Girls | Google |

Behat + Mink + Selenium2 = YEAH!

Generated snippet<?php

use Behat\Behat\Tester\Exception\PendingException;use Behat\MinkExtension\Context\MinkContext;use Behat\Behat\Context\SnippetAcceptingContext;

class WebContext extends MinkContext implements SnippetAcceptingContext{ /** * @Given the visitor is from :arg1 */ public function theVisitorIsFrom($arg1) { throw new PendingException(); }

/** * @When the visitor is on the :arg1 page */ public function theVisitorIsOnThePage($arg1) { throw new PendingException(); }

/** * @When the visitor is on the :arg1 channel */ public function theVisitorIsOnTheChannel($arg1) { throw new PendingException(); } /** * @Then advertisements should be served by :provider */ public function advertisementsShouldBeServedBy($provider) { throw new PendingException(); }}

Enter some logic<?php

use Behat\Behat\Tester\Exception\PendingException;use Behat\MinkExtension\Context\MinkContext;use Behat\Behat\Context\SnippetAcceptingContext;

class WebContext extends MinkContext implements SnippetAcceptingContext{ private $pages = array( 'default' => '/', 'home' => '/', 'game' => '/spel/donuts-saras-kookcursus' ); private $channels = array( 'Teens' => 'http://www.agame.com', 'Girls' => 'http://www.girlsgogames.com', 'Family' => 'http://spel.nl' ); /** * @Given the visitor is from :country */ public function theVisitorIsFrom($country) { $this->getSession()->setCookie('country', $country); }

/** * @When the visitor is on the :page page */ public function theVisitorIsOnThePage($page) { $this->visitPath($this->pages[$page]); }

/** * @When the visitor is on the :arg1 channel */ public function theVisitorIsOnTheChannel($channel) { $this->setMinkParameter('base_url', $this->channels[$channel]); } /** * @Then advertisements should be served by :provider */ public function advertisementsShouldBeServedBy($provider) { // provider check... }}

Tested 5 scenarios in 10 seconds.

Questions?