EFFECTIVE TESTING USING
BEHAVIOUR-DRIVEN
DEVELOPMENT
Alexander Kress
About me
• Development manager at RedFlagDeals.com
• Worked with BDD based testing for 3 years
• Blog devmngr.wordpress.com
• Twitter @al3xkress
Test Driven Development
• Add a test
• Run all tests and see if the new one fails
• Write some code
• Run the automated tests and see them
succeed
• Refactor code
• Repeat
From Wikipedia
From TDD to BDD
• TDD is a developer concept
• I want QA to be involved
• I want PO to be involved
• I want any random person on the street to
understand
Behavior Driven Development
BDD is a second-generation, outside–in,
pull-based, multiple-stakeholder, multiple-
scale, high-automation, agile methodology. It
describes a cycle of interactions with well-
defined outputs, resulting in the delivery of
working, tested software that matters.
Dan North
Gherkin – the language
Feature: Some terse yet descriptive text of what is desired
In order to realize a named business value.
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
And yet another action
Then some testable outcome is achieved
And something else we can check happens too
Behat documentation
Effective Testing using Behavior-Driven Development
Gherkin – example
Feature: “Who viewed your profile” page displays a list of
recent visitors
Scenario: Profile visit is reflected on Profile stats page
Given “Waikei” has recently visited “Alex” profile
When I login as “Alex”
And go to my “Profile stats” page
Then I see that “Waikei” has visited my profile
And can see that “Waikei” works in “Publishing”
Behat – PHP BDD Framework
• Clone of Cucumber – Ruby BDD framework
• Quick composer based install
• Great documentation
• But what does it do?
– Steps!
Effective Testing using Behavior-Driven Development
Behat – Writing steps
/**
* @Given /^"([^"]*)" has recently visited "([^"]*)" profile$/
*/
public function hasRecentlyVisitedProfile($visitor, $host)
{
#insert a visit from $visitor to $host into the visits table
#fail if $visitor or $host do not exist
}
General Guidelines for writing steps:
• Make steps reusable
• Keep them short and simple
• Refactor all the time
Behat – Syntactic sugar
Tables
Then I see the following visitors to my profile
| Visitor| Industry |
| Waikei | Publishing |
| Nancy | IT |
| Brian | Education |
Pystrings
Given I make a “GET” request to “URL” I receive
”””
{
"status":200,
“num_results":100
…
}
”””
Mink
• Composer based install
• Supports
– Selenium Driver
– Web Driver (Selenium 2)
– Sahi and others
• “removes API differences between different
browser emulators”
Mink - example
/**
* @Then /^I see that "([^"]*)" has visited my profile$/
*/
public function iSeeThatHasVisitedMyProfile($guest)
{
#Assuming that the browser is current on the “Profile stats”
#the simplest method, just search the page
if (strpos($this->getMainSession()->getPage()->getText(),
$guest)===false) {
throw new Exception("Could not find " . $text . " on page");
}
}
public function getMainSession() {
return $this->getMainContext()->getSession();
}
Mink – useful methods
• Named selectors: link, button, content, etc
• CSS, XPath selectors
• Form field manipulation
• Mouse operations
• Custom js execution
Effective Testing using Behavior-Driven Development
Extending Behat and Mink
• phpunit
• Database injection
• Mocks
• Code coverage
This will never work!
Do BDDs remind you of anything?
User Stories!
Who thinks in user stories?
Product Owners
It does work!
• Convince everyone that BDDs are awesome
• PO write requirements in BDD scenarios
• QA review and validate early
• Developers write BDD steps
• QA augment developer BDD steps and create
new scenarios and steps
BDDs are a major part of the process
It does work!
• No v5.3 of the Spec!
• Everyone knows what the PO meant
• QA are assisted by developers
• No spec!
Be careful what you test for
Other things to watch our for
• Maintainability (XPaths, CSS paths)
• Coding to test
• Step duplication
• Length of execution
Who uses BDDs
Other resources
http://www.slideshare.net/NgTzeYang/the-lazy-
developers-guide-to-bdd-with-cucumber
Tomorrow! - Webinar - Behavior Driven
Development with Behat
http://qafoo.com/blog/042_webinar_bdd_behat.
html
Links
http://behat.org/
http://mink.behat.org/
http://en.wikipedia.org/wiki/Behavior-
driven_development
QUESTIONS?

More Related Content

PDF
素晴らしきJSの世界とSEO 20170606 we are_javascripters@8th
PDF
Brownbag on basics of web components
KEY
Extending Custom Post Types
KEY
doing_it_right() with WordPress
PDF
JSの知識だけでLINE Bot作ってみる! 20170327_we are_javascripters@5th
PDF
Jekyll Presentation Slides
PPTX
Jekyll, static websites generator
PPTX
Front End Web Development Basics
素晴らしきJSの世界とSEO 20170606 we are_javascripters@8th
Brownbag on basics of web components
Extending Custom Post Types
doing_it_right() with WordPress
JSの知識だけでLINE Bot作ってみる! 20170327_we are_javascripters@5th
Jekyll Presentation Slides
Jekyll, static websites generator
Front End Web Development Basics

What's hot (20)

ODP
Introduction to blogging with Jekyll
PPTX
Creating better behat features
PDF
Building Awesome Apps with Angular and Firebase
PDF
Webinar: Getting Started with Ruby and MongoDB
PPTX
Untangling - fall2017 - week 9
PPTX
Untangling spring week4
PPTX
Put a little Backbone in your WordPress
PDF
Search as main navigation
PPTX
Untangling spring week5
PPTX
Untangling - fall2017 - week 10
PPT
WordPress Harrisburg Meetup - Best Practices
PDF
When all you have is a hammer, everything looks like Javascript - ebookcraft ...
PDF
Introduction to html & css
PPTX
Untangling11
PPTX
Harness jQuery Templates and Data Link
PDF
Git your Jekyll on - WebCamp Ljubljana 2015
PPTX
Introduction to Jquery
PPT
Website Design, Development & Maintenance | Foundations | Week 01
PPT
Expert guide for PHP
PPTX
Web scraping 101 with goutte
Introduction to blogging with Jekyll
Creating better behat features
Building Awesome Apps with Angular and Firebase
Webinar: Getting Started with Ruby and MongoDB
Untangling - fall2017 - week 9
Untangling spring week4
Put a little Backbone in your WordPress
Search as main navigation
Untangling spring week5
Untangling - fall2017 - week 10
WordPress Harrisburg Meetup - Best Practices
When all you have is a hammer, everything looks like Javascript - ebookcraft ...
Introduction to html & css
Untangling11
Harness jQuery Templates and Data Link
Git your Jekyll on - WebCamp Ljubljana 2015
Introduction to Jquery
Website Design, Development & Maintenance | Foundations | Week 01
Expert guide for PHP
Web scraping 101 with goutte
Ad

Viewers also liked (20)

PDF
Beyond Testing: Specs and Behavior Driven Development
PPTX
Calabash
KEY
Behavior driven development
PDF
Behavior Driven GUI Testing
PPT
Behavior Driven Development with Rails
PDF
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
PDF
Behavior Driven Testing goes Mobile!
PDF
BDD training v5.0.1
PDF
German Testing Day 2015 - How behavior-driven development fuses developers an...
PDF
Behavior driven development. Testing drupal using behat
PPTX
Behavior Driven Testing of Web Services
PDF
Startup Institute: JS Testing & Behavior Driven Development
PPTX
Behavior Driven Development
PPTX
Behavior Driven Testing for Multichannel Enterprise Applications
PDF
Building the "right" regression suite using Behavior Driven Testing (BDT)
PPTX
BDD / cucumber /Capybara
PDF
Behavior Driven Testing - A paradigm shift
PPTX
[Agile Testing Day] Behavior Driven Development (BDD)
KEY
Natural Language UI Testing using Behavior Driven Development with Pavlov and...
PPTX
Behavior Driven Development Testing (BDD)
Beyond Testing: Specs and Behavior Driven Development
Calabash
Behavior driven development
Behavior Driven GUI Testing
Behavior Driven Development with Rails
Unit Testing and Behavior Driven Testing with AngularJS - Jesse Liberty | Fal...
Behavior Driven Testing goes Mobile!
BDD training v5.0.1
German Testing Day 2015 - How behavior-driven development fuses developers an...
Behavior driven development. Testing drupal using behat
Behavior Driven Testing of Web Services
Startup Institute: JS Testing & Behavior Driven Development
Behavior Driven Development
Behavior Driven Testing for Multichannel Enterprise Applications
Building the "right" regression suite using Behavior Driven Testing (BDT)
BDD / cucumber /Capybara
Behavior Driven Testing - A paradigm shift
[Agile Testing Day] Behavior Driven Development (BDD)
Natural Language UI Testing using Behavior Driven Development with Pavlov and...
Behavior Driven Development Testing (BDD)
Ad

Similar to Effective Testing using Behavior-Driven Development (20)

PDF
Bridging the gap between business and technology - Behaviour Driven Developme...
PPTX
A step-by-step guide to behavior-driven development
PDF
Behat - Drupal Yorkshire
PPTX
Behat - human-readable automated testing
PPTX
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...
PPTX
BDD in my team: how we do it
PPTX
Behavioral tests with behat for qa
PPTX
Bdd and Behat
PPTX
Bdd. Automate your requirements
PDF
BDD with Gauge
PDF
Gauge your BDD Test (vodQA Hyderabad)
PDF
Gauge your BDD Test (vodQA Hyderabad)
ODP
BDD with Behat
PDF
Behavior Driven Development with Drupal
PDF
Behavioral Driven Development
PDF
Behavior Driven Development—A Guide to Agile Practices
PPT
BDD along with Continuous Integration
PPT
Stc 2015 regional-round-ppt-bdd along with ci
PPTX
Design your tests to behave - An introduction To BDD!
ODP
2014 11 20 Drupal 7 -> 8 test migratie
Bridging the gap between business and technology - Behaviour Driven Developme...
A step-by-step guide to behavior-driven development
Behat - Drupal Yorkshire
Behat - human-readable automated testing
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...
BDD in my team: how we do it
Behavioral tests with behat for qa
Bdd and Behat
Bdd. Automate your requirements
BDD with Gauge
Gauge your BDD Test (vodQA Hyderabad)
Gauge your BDD Test (vodQA Hyderabad)
BDD with Behat
Behavior Driven Development with Drupal
Behavioral Driven Development
Behavior Driven Development—A Guide to Agile Practices
BDD along with Continuous Integration
Stc 2015 regional-round-ppt-bdd along with ci
Design your tests to behave - An introduction To BDD!
2014 11 20 Drupal 7 -> 8 test migratie

Recently uploaded (20)

PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Unlock new opportunities with location data.pdf
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPTX
Modernising the Digital Integration Hub
PPT
What is a Computer? Input Devices /output devices
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
The various Industrial Revolutions .pptx
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
CloudStack 4.21: First Look Webinar slides
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Architecture types and enterprise applications.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
A novel scalable deep ensemble learning framework for big data classification...
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Unlock new opportunities with location data.pdf
Web Crawler for Trend Tracking Gen Z Insights.pptx
Modernising the Digital Integration Hub
What is a Computer? Input Devices /output devices
Getting Started with Data Integration: FME Form 101
Final SEM Unit 1 for mit wpu at pune .pptx
The various Industrial Revolutions .pptx
sustainability-14-14877-v2.pddhzftheheeeee
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Module 1.ppt Iot fundamentals and Architecture
Benefits of Physical activity for teenagers.pptx
CloudStack 4.21: First Look Webinar slides
Hindi spoken digit analysis for native and non-native speakers
Architecture types and enterprise applications.pdf
NewMind AI Weekly Chronicles – August ’25 Week III
WOOl fibre morphology and structure.pdf for textiles
A novel scalable deep ensemble learning framework for big data classification...

Effective Testing using Behavior-Driven Development

  • 2. About me • Development manager at RedFlagDeals.com • Worked with BDD based testing for 3 years • Blog devmngr.wordpress.com • Twitter @al3xkress
  • 3. Test Driven Development • Add a test • Run all tests and see if the new one fails • Write some code • Run the automated tests and see them succeed • Refactor code • Repeat From Wikipedia
  • 4. From TDD to BDD • TDD is a developer concept • I want QA to be involved • I want PO to be involved • I want any random person on the street to understand
  • 5. Behavior Driven Development BDD is a second-generation, outside–in, pull-based, multiple-stakeholder, multiple- scale, high-automation, agile methodology. It describes a cycle of interactions with well- defined outputs, resulting in the delivery of working, tested software that matters. Dan North
  • 6. Gherkin – the language Feature: Some terse yet descriptive text of what is desired In order to realize a named business value. Scenario: Some determinable business situation Given some precondition And some other precondition When some action by the actor And some other action And yet another action Then some testable outcome is achieved And something else we can check happens too Behat documentation
  • 8. Gherkin – example Feature: “Who viewed your profile” page displays a list of recent visitors Scenario: Profile visit is reflected on Profile stats page Given “Waikei” has recently visited “Alex” profile When I login as “Alex” And go to my “Profile stats” page Then I see that “Waikei” has visited my profile And can see that “Waikei” works in “Publishing”
  • 9. Behat – PHP BDD Framework • Clone of Cucumber – Ruby BDD framework • Quick composer based install • Great documentation • But what does it do? – Steps!
  • 11. Behat – Writing steps /** * @Given /^"([^"]*)" has recently visited "([^"]*)" profile$/ */ public function hasRecentlyVisitedProfile($visitor, $host) { #insert a visit from $visitor to $host into the visits table #fail if $visitor or $host do not exist } General Guidelines for writing steps: • Make steps reusable • Keep them short and simple • Refactor all the time
  • 12. Behat – Syntactic sugar Tables Then I see the following visitors to my profile | Visitor| Industry | | Waikei | Publishing | | Nancy | IT | | Brian | Education | Pystrings Given I make a “GET” request to “URL” I receive ””” { "status":200, “num_results":100 … } ”””
  • 13. Mink • Composer based install • Supports – Selenium Driver – Web Driver (Selenium 2) – Sahi and others • “removes API differences between different browser emulators”
  • 14. Mink - example /** * @Then /^I see that "([^"]*)" has visited my profile$/ */ public function iSeeThatHasVisitedMyProfile($guest) { #Assuming that the browser is current on the “Profile stats” #the simplest method, just search the page if (strpos($this->getMainSession()->getPage()->getText(), $guest)===false) { throw new Exception("Could not find " . $text . " on page"); } } public function getMainSession() { return $this->getMainContext()->getSession(); }
  • 15. Mink – useful methods • Named selectors: link, button, content, etc • CSS, XPath selectors • Form field manipulation • Mouse operations • Custom js execution
  • 17. Extending Behat and Mink • phpunit • Database injection • Mocks • Code coverage
  • 18. This will never work! Do BDDs remind you of anything? User Stories! Who thinks in user stories? Product Owners
  • 19. It does work! • Convince everyone that BDDs are awesome • PO write requirements in BDD scenarios • QA review and validate early • Developers write BDD steps • QA augment developer BDD steps and create new scenarios and steps BDDs are a major part of the process
  • 20. It does work! • No v5.3 of the Spec! • Everyone knows what the PO meant • QA are assisted by developers • No spec!
  • 21. Be careful what you test for
  • 22. Other things to watch our for • Maintainability (XPaths, CSS paths) • Coding to test • Step duplication • Length of execution
  • 24. Other resources http://www.slideshare.net/NgTzeYang/the-lazy- developers-guide-to-bdd-with-cucumber Tomorrow! - Webinar - Behavior Driven Development with Behat http://qafoo.com/blog/042_webinar_bdd_behat. html