• Like
  • Save
It should! - BDD in practice
Upcoming SlideShare
Loading in...5
×
 

It should! - BDD in practice

on

  • 799 views

How BDD helps you solve the murder on the Orient Express

How BDD helps you solve the murder on the Orient Express

Statistics

Views

Total Views
799
Views on SlideShare
782
Embed Views
17

Actions

Likes
5
Downloads
12
Comments
1

3 Embeds 17

http://www.linkedin.com 7
https://www.linkedin.com 7
https://twitter.com 3

Accessibility

Upload Details

Uploaded via as Adobe PDF

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

11 of 1

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

    It should! - BDD in practice It should! - BDD in practice Presentation Transcript

    • IT SHOULD! BDD IN PRACTICE
    • BEHAVIOR DRIVEN DEVELOPMENT = TEST DRIVEN DEVELOPMENT exceptit's done right
    • TDD IS CODE-CENTRIC WHILE BDD IS COMMUNICATION-CENTRIC
    • IT'S LIKE COKE PEPSI = COCA-COLA exceptit's done right
    • BUT THIS IS NOT ABOUT WHAT BDD MEANS THIS IS ALL ABOUT TOOLS AND ...
    • THE MURDER ON THE ORIENT EXPRESS
    • MA'AM! CAN YOU TEST WHO YOU SAW? "Whatdo you mean test?Ican describe itif you like"-Ma'am ./bin/phpspecdescSuspect
    • THE SUSPECTS "He was one of those types, you know"-Ma'am namespacespecOrientExpressSuspect; usePhpSpecObjectBehavior; useProphecyArgument; classSuspectSpecextendsObjectBehavior { functionit_is_initializable() { $this->shouldHaveType('OrientExpressSuspectSuspect'); } }
    • THE SUSPECTS "Don'tyell atme!Be adear and help me out."-Ma'am
    • THE SUSPECTS namespacespecOrientExpressSuspect; usePhpSpecObjectBehavior; useProphecyArgument; classSuspectSpecextendsObjectBehavior { //... functionit_should_answer_questions() { $this->answer('Areyouthekiller?') ->shouldReturn('Nope,notme'); } }
    • THE SUSPECTS
    • THE SUSPECTS namespaceOrientExpressSuspect; classSuspect { publicfunctionanswer($question) { return'Nope,notme'; } }
    • THE SUSPECTS - REFACTORING MADE EASY "Oh, Ijustremembered!"-Ma'am namespacespecOrientExpressSuspect; usePhpSpecObjectBehavior; useProphecyArgument; classSuspectSpecextendsObjectBehavior { //... functionit_should_not_confess_to_wrong_questions_if_guilty() { $this->setGuilty(true); $this->answer('Areyouthekiller?') ->shouldReturn('Nope,notme'); } }
    • THE SUSPECTS - REFACTORING MADE EASY "Oh, Ijustremembered!"-Ma'am namespacespecOrientExpressSuspect; usePhpSpecObjectBehavior; useProphecyArgument; classSuspectSpecextendsObjectBehavior { //... functionit_should_confess_to_key_question_if_guilty() { $this->setGuilty(true); $this->answer('Itwasyou!') ->shouldReturn('MmmkayIconfess'); } }
    • THE SUSPECTS namespaceOrientExpressSuspect; classSuspect { protected$keyQuestion='Itwasyou!'; protected$guilty=false; publicfunctionanswer($question) { if($this->guilty&&$question==$this->keyQuestion){ return'MmmkayIconfess'; } return'Nope,notme'; } //... }
    • SIR! CAN YOU DESCRIBE WHO SOLVED IT? ./bin/phpspecdescDetective
    • THE OLDSCHOOL DETECTIVE //OppaPHPUnitstyle functiontestSolve() { //... $crime=$this->getMock('OrientExpressCrimeCrime', array('getSuspects')); $crime->expects($this->any()) ->method('getSuspects') ->will($this->returnValue(array($suspect1,$suspect2)); //NoOoOoooOoOoOoo!!! }
    • THE DETECTIVE classDetectiveSpecextendsObjectBehavior { //... /** *@paramOrientExpressCrimeCrime$crime *@paramOrientExpressSuspectSuspect$suspect1 *@paramOrientExpressSuspectSuspect$suspect2 */ functionit_should_be_able_to_solve_crimes($crime,$suspect1, $suspect2) { $crime->getSuspects() ->willReturn(array($suspect1,$suspect2)); $suspect1->answer('Itwasyou!') ->willReturn('Nope,notme'); $suspect2->answer('Itwasyou!') ->willReturn('MmmkayIconfess'); $this->solve($crime)->shouldReturn($suspect2); } }
    • THE DETECTIVE namespaceOrientExpressInvestigators; useOrientExpressCrimeCrime; classDetective { publicfunctionsolve(Crime$crime) { foreach($crime->getSuspects()as$suspect){ $answer=$suspect->answer('Itwasyou!'); if(preg_match('/confess/',$answer)){ return$suspect; } } } }
    • WORKS AS DESCRIBED
    • WHAT ABOUT THE SCOTLAND YARD?
    • DOES THE POLICE FUNCTION PROPERLY? Feature: Inordertoknowthecrimesonorientexpress AsaScotlandYardAPIclient Iwanttogetaccesstothearchives
    • DOES THE POLICE FUNCTION PROPERLY? Background: Giventhefollowingcrimesexist: |name | |"MurderontheOrientExpress"| Andthefollowingdetectivesexist: |name | |"HerculsePoirot"| Andthefollowingsuspectsexist: |name | |"PrincessDragomiroff"| |"CountAdrenyi" |
    • DOES THE POLICE FUNCTION PROPERLY?
    • Scenario:GettingdatafromtheScotlandYard'sarchives Givencrime"MurderontheOrientExpress"wassolvedby"HerculesPoirot " Andcrime"MurderontheOrientExpress"hadsuspects: |name | |"PrincessDragomiroff"| |"CountAdrenyi" | WhenIsendGETrequestto"/api/crimes/ORIENT_EXPRESS_CRIME_ID" Thentheresponseshouldcontainjson: """ { "crime":{ "name":"MurderontheOrientExpress", "detective":{ "name":"HerculesPoirot" }, "suspects":[ { "name":"PrincesDragomiroff" }, { "name":"CountAdrenyi" } ] } } """
    • WHY IS THIS SO IMPORTANT? BECAUSE EVERY CODE TELLS A STORY OR AT LEAST IT SHOULD!
    • ? PhpSpec: Behat: Specs: ABOUT ME KarolSójko LeadSoftware Architect @ Twitter: Github: https://github.com/phpspec/phpspec https://github.com/Behat/Behat https://github.com/karolsojko/bdd-in-practice The CometCult @karolsojko karolsojko