effective testing using behavior-driven development
DESCRIPTION
A talk on BDDs, Behat and the processTRANSCRIPT
![Page 1: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/1.jpg)
EFFECTIVE TESTING USING BEHAVIOUR-DRIVEN
DEVELOPMENT
Alexander Kress
![Page 2: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/2.jpg)
About me
• Development manager at RedFlagDeals.com• Worked with BDD based testing for 3 years• Blog devmngr.wordpress.com • Twitter @al3xkress
![Page 3: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/3.jpg)
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
![Page 4: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/4.jpg)
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
![Page 5: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/5.jpg)
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
![Page 6: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/6.jpg)
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
![Page 7: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/7.jpg)
![Page 8: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/8.jpg)
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”
![Page 9: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/9.jpg)
Behat – PHP BDD Framework
• Clone of Cucumber – Ruby BDD framework• Quick composer based install• Great documentation• But what does it do?– Steps!
![Page 10: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/10.jpg)
![Page 11: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/11.jpg)
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
![Page 12: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/12.jpg)
Behat – Syntactic sugarTables
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…}”””
![Page 13: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/13.jpg)
Mink
• Composer based install• Supports– Selenium Driver– Web Driver (Selenium 2)– Sahi and others
• “removes API differences between different browser emulators”
![Page 14: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/14.jpg)
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(); }
![Page 15: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/15.jpg)
Mink – useful methods
• Named selectors: link, button, content, etc• CSS, XPath selectors• Form field manipulation• Mouse operations• Custom js execution
![Page 16: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/16.jpg)
![Page 17: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/17.jpg)
Extending Behat and Mink
• phpunit• Database injection• Mocks• Code coverage
![Page 18: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/18.jpg)
This will never work!
Do BDDs remind you of anything?
User Stories!
Who thinks in user stories?
Product Owners
![Page 19: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/19.jpg)
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
![Page 20: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/20.jpg)
It does work!
• No v5.3 of the Spec!• Everyone knows what the PO meant• QA are assisted by developers• No spec!
![Page 21: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/21.jpg)
Be careful what you test for
![Page 22: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/22.jpg)
Other things to watch our for
• Maintainability (XPaths, CSS paths)• Coding to test• Step duplication• Length of execution
![Page 23: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/23.jpg)
Who uses BDDs
![Page 24: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/24.jpg)
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
![Page 25: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/25.jpg)
Links
http://behat.org/
http://mink.behat.org/
http://en.wikipedia.org/wiki/Behavior-driven_development
![Page 26: Effective Testing using Behavior-Driven Development](https://reader035.vdocuments.net/reader035/viewer/2022062703/554cb4cdb4c905335b8b4e56/html5/thumbnails/26.jpg)
QUESTIONS?