Effective Testing using Behavior-Driven Development
Upcoming SlideShare
Loading in...5
×
 

Effective Testing using Behavior-Driven Development

on

  • 1,016 views

A talk on BDDs, Behat and the process

A talk on BDDs, Behat and the process

Statistics

Views

Total Views
1,016
Views on SlideShare
597
Embed Views
419

Actions

Likes
0
Downloads
10
Comments
0

2 Embeds 419

http://devmngr.wordpress.com 418
http://plus.url.google.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Effective Testing using Behavior-Driven Development Effective Testing using Behavior-Driven Development Presentation Transcript

  • EFFECTIVE TESTING USINGBEHAVIOUR-DRIVENDEVELOPMENTAlexander 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 themsucceed• Refactor code• RepeatFrom 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 tounderstand
  • Behavior Driven DevelopmentBDD is a second-generation, outside–in,pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology. Itdescribes a cycle of interactions with well-defined outputs, resulting in the delivery ofworking, tested software that matters.Dan North
  • Gherkin – the languageFeature: Some terse yet descriptive text of what is desiredIn order to realize a named business value.Scenario: Some determinable business situationGiven some preconditionAnd some other preconditionWhen some action by the actorAnd some other actionAnd yet another actionThen some testable outcome is achievedAnd something else we can check happens tooBehat documentation
  • Gherkin – exampleFeature: “Who viewed your profile” page displays a list ofrecent visitorsScenario: Profile visit is reflected on Profile stats pageGiven “Waikei” has recently visited “Alex” profileWhen I login as “Alex”And go to my “Profile stats” pageThen I see that “Waikei” has visited my profileAnd 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!
  • 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 sugarTablesThen I see the following visitors to my profile| Visitor| Industry || Waikei | Publishing || Nancy | IT || Brian | Education |PystringsGiven 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 differentbrowser 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 pageif (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
  • 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 createnew scenarios and stepsBDDs 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 resourceshttp://www.slideshare.net/NgTzeYang/the-lazy-developers-guide-to-bdd-with-cucumberTomorrow! - Webinar - Behavior DrivenDevelopment with Behathttp://qafoo.com/blog/042_webinar_bdd_behat.html
  • Linkshttp://behat.org/http://mink.behat.org/http://en.wikipedia.org/wiki/Behavior-driven_development
  • QUESTIONS?