SlideShare ist ein Scribd-Unternehmen logo
1 von 85
Downloaden Sie, um offline zu lesen
Acceptance &
                        Integration
                       Testing Using
                           Behat
                                Ben Waine
                        Email: ben@ben-waine.co.uk
                             Twitter: @bwaine


Sunday, 9 October 11
Roadmap
         •Intro To Behaviour Driven Development
         •Problems We Are Trying to solve at Sky With
         BDD
         •Behat
         •API Testing with Behat
         •UI Testing with Behat
         •Data Driven Testing
         •Is Behat solving our problem?
Sunday, 9 October 11
Me
          Software Engineer
          PHP Developer



         Sky Bet
         PHP / MySQL Stack
        PHPUnit / Selenium / Behat



Sunday, 9 October 11
Behaviour
                       Driven Development
                              (BDD)



Sunday, 9 October 11
Behaviour-driven development (BDD)
               takes the position that you can turn an
               idea for a requirement into implemented,
               tested, production-ready code simply and
               effectively, as long as .... everyone knows
               what’s going on.


                                         - Dan North




Sunday, 9 October 11
Writing tests first in a customer
                friendly language
                            - Drinkwater et al 2011




Sunday, 9 October 11
The Problem




Sunday, 9 October 11
The Business
          Analyst
Sunday, 9 October 11
The Tester




Sunday, 9 October 11
The
                       Developer
Sunday, 9 October 11
The Problem




Sunday, 9 October 11
Behat




Sunday, 9 October 11
Resistance is futile.......
Sunday, 9 October 11
What Does It Test?

                             Scripts
                              API’s
                            Web Pages
                             Models




Sunday, 9 October 11
Integration Testing
                                !=
                          Unit Testing



Sunday, 9 October 11
Anatomy Of A Behat Test




Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
My Amazing PHP Conference
                        Website!




Sunday, 9 October 11
Writing Behat Tests

                       $ben > cd /path/to/projects/tests
                       $ben > behat --init




Sunday, 9 October 11
Writing Behat Tests




Sunday, 9 October 11
Feature Files

         Feature: Home Page
                  When visiting the PHPCon site
                  As a site visitor
                  I need to be able to see what
         `        conferences are coming up




Sunday, 9 October 11
Scenarios
Scenario: Get all conferences
    Given there is conference data in the database
    When I go to the homepage
    Then I should see three conferences in a table




Sunday, 9 October 11
Scenarios
                           Given
                       (Some Context)

                           When
                        (Some Event)

                           Then
                       (The Outcome)


Sunday, 9 October 11
Given
                       (Some Context)
           Given there is conference data in the database




Sunday, 9 October 11
When
                                 (Some Event)
                             When I go to the homepage

                        When I use the findConferences method
                              When I am on "/index.php"

                       When I fill in "search-text" with "PHP"




Sunday, 9 October 11
Then
                         (The Outcome)
           Then I should see three conferences in a table

           Then I should get a array of three conferences

                       Then I should see "PHPNW"




Sunday, 9 October 11
ConferenceService.feature

      Feature: ConferenceService Class
               In order to display conferences on
               PHPCon site
               As a developer
               I need to be able to retrieve conferences

      Scenario: Get all conferences
          Given there is conference data in the database
          When I use the findConferences method
          Then I should get a array of three conferences
                       AND it should contain the conference “PHPNW”




Sunday, 9 October 11
Class Methods & Annotations




Sunday, 9 October 11
/ Everybody Stand Back /
                Behat Knows Regular Expressions




Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Copy and paste these methods
                 into FeatureContext.php




Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Fill in the Feature Context File
          public function __construct(array $parameters)
          {
              $params = array(
                  'user' => $parameters['database']['username'],
                  'password' => $parameters['database']['password'],
                  'driver' => $parameters['database']['driver'],
                  'path' => $parameters['database']['dbPath'],
              );

                       $con = DoctrineDBALDriverManager::getConnection($params);

                       $confMapper = new PHPConConferenceMapper($con);
                       $confService = new PHPConConferenceService($confMapper);

                       $this->service = $confService;
          }



Sunday, 9 October 11
Fill in the Feature Context File

        /**
          * @Given /^there is conference data in the database$/
          */
        public function thereIsConferneceDataInTheDatabase()
        {
             $fileName = self::$dataDir .
             'sample-conf-session-data.sql';
             self::executeQueriesInFile($fileName);
        }




Sunday, 9 October 11
Fill in the Feature Context File

           /**
             * @When /^I use the findConferences method$/
             */
           public function iUseTheFindConferencesMethod()
           {
                $this->result = $this->service->findConferences();

           }




Sunday, 9 October 11
Fill in the Feature Context File
           /**
             *@Then /^I should get an array of (d+) conferences$/
             */
           public function iShouldGetAnArrayOfConferences
                                           ($numberOfCons)
           {
                assertInternalType('array', $this->result);
                assertEquals($numberOfCons, count($this->result));
           }




Sunday, 9 October 11
/**
                   * @Then /^it should contain the
                   * conference "([^"]*)"$/
                   */
                 public function itShouldContainTheConference
                                                   ($confName)
                 {
                      $names = array();

                       foreach($this->result as $conf)
                       {
                           $names[$conf->getName()] = true;
                       }

                       if(!array_key_exists($confName, $names))
                       {
                           throw new Exception("Conference "
                           . $confName . " not found");
                       }
                 }

Sunday, 9 October 11
Ready to run the tests again.....




Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Failing Test




Sunday, 9 October 11
Add some application code.....




Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Passing Test!




Sunday, 9 October 11
What about the UI?




Sunday, 9 October 11
Mink




Sunday, 9 October 11
Mink


                       Goutte           Sahi




                            Zombie.js



Sunday, 9 October 11
Extend Mink Context

                       Includes predefined steps

                   Use Bundled steps to create
                    higher level abstractions.


Sunday, 9 October 11
Back To:
                My Amazing PHP Conference
                        Website!



Sunday, 9 October 11
Example

                       Using Minks Bundled Steps

  Scenario: View all conferences on the homepage
      Given there is conference data in the database
      When I am on "/index.php"
      Then I should see "PHPNW" in the ".conferences" element
      And I should see "PHPUK" in the ".conferences" element
      And I should see "PBC11" in the ".conferences" element




Sunday, 9 October 11
class FeatureContext

                       public function __construct(array $parameters)
                       {
                           $this->useContext('subcontext_alias',
                                             new UIContext($parameters));

             !     // REST OF FEATURE CONSTRUCTOR

                       }




             # features/bootstrap/UIContext.php

             use BehatBehatContextClosuredContextInterface,
                 BehatBehatContextBehatContext,
                 BehatBehatExceptionPendingException;

             use BehatGherkinNodePyStringNode,
                 BehatGherkinNodeTableNode;

             require_once 'mink/autoload.php';

             class UIContext extends BehatMinkBehatContextMinkContext
             {

             }


Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Sunday, 9 October 11
Powerful Headless UI
                        Testing Out The Box




Sunday, 9 October 11
Abstracting your scenario

 Scenario: View all conferences on the homepage
     Given there is conference data in the database
     When I am on the "home" page
     Then I should see "PHPNW" in the "conferences" table
     And I should see "PHPUK" in the "conferences" table
     And I should see "PBC11" in the "conferences" table




Sunday, 9 October 11
Mink Feature Context

 class UIContext extends BehatMinkBehatContext
 MinkContext
 {
     protected $pageList = array(
                             "home" => '/index.php');
     protected $elementList = array(
                   "conferences table" => '.conferences');




Sunday, 9 October 11
/**
              * @When /^I am on the "([^"]*)" page$/
              */
             public function iAmOnThePage($pageName) {

                       if(!isset($this->pageList[$pageName])) {
                           throw new Exception(
                                   'Page Name: not in page list');
                       }

                       $page = $this->pageList[$pageName];

                       return new When("I am on "$page"");
             }




Sunday, 9 October 11
/**
             * @Then /^I should see "([^"]*)" in the "([^"]*)"$/
             */
            public function iShouldSeeInThe($text, $element) {
                if(!isset($this->elementList[$element])) {
                     throw new Exception(
                  'Element: ' . $element . ‘not in element list');
                }
                $element = $this->elementList[$element];

         return
         new Then("I should see "$text" in then
 "$element" element");
     }




Sunday, 9 October 11
Javascript Testing with.....



                                  Sahi




Sunday, 9 October 11
Back To:
                My Amazing PHP Conference
                        Website!



Sunday, 9 October 11
Example
          @javascript
          Scenario: Use autocomplete functionality to
          complete a input field
              Given there is conference data in the
          database
              When I am on the "home" page
              When I fill in "search-text" with "PHP"
              And I wait for the suggestion box to appear
              Then I should see "PHPNW"




Sunday, 9 October 11
Great Reuse

             @javascript
             Scenario: Use autocomplete functionality to
             complete a input field
                 Given there is conference data in the
             database
                 When I am on the "home" page
                 When I fill in "search-text" with "PHP"
                 And I wait for the suggestion box to appear
                 Then I should see "PHPNW"




Sunday, 9 October 11
// In the UIContext class
                       /**
                          * @Given /^I wait for the suggestion box to appear$/
                          */
                        public function iWaitForTheSuggestionBoxToAppear()
                        {
                             $this->getSession()->wait(5000,
                                 "$('.suggestions-results').children().length > 0"
                             );
                        }




Sunday, 9 October 11
Sunday, 9 October 11
Data




Sunday, 9 October 11
SQL Fixture




Sunday, 9 October 11
Phabric




Sunday, 9 October 11
Phabric
                       Inserting Data From Gherkin Tables

   Scenario:
       Given The       following events   exist
       | Name |        Date               | Venue                  | Desc             |
       | PHPNW |       2011-10-08 09:00   | Ramada Hotel           | Awesome conf!    |
       | PHPUK |       2012-02-27 09:00   | London Business Center | Quite good conf. |



           INSERT INTO event `Name`, `Date`, `Venue`, `Desc`
           VALUE
           (‘PHPNW’, ‘2011-10-08 09:00’, ‘Ramada Hotel’,
           ‘Awesome Conf!’)
Sunday, 9 October 11
Phabric
                   Transforming Table Headings to DB col names

   Scenario:
       Given The       following events   exist
       | Name |        Date               | Venue                  | Desc             |
       | PHPNW |       2011-10-08 09:00   | Ramada Hotel           | Awesome conf!    |
       | PHPUK |       2012-02-27 09:00   | London Business Center | Quite good conf. |



          INSERT INTO event `name`, `date`, `venue`, `description`
          VALUE
          (‘PHPNW’, ‘2011-10-08 09:00’, ‘Ramada Hotel’,
          ‘Awesome Conf!’)
Sunday, 9 October 11
Phabric
         Transforming Table data using user defined callbacks

   Scenario:
       Given The       following events   exist
       | Name |        Date               | Venue                  | Desc             |
       | PHPNW |       08/10/2011 09:00   | Ramada Hotel           | Awesome conf!    |
       | PHPUK |       27/02/2012 09:00   | London Business Center | Quite good conf. |


      INSERT INTO event `name`, `date`, `venue`, `description`
      VALUE
      (‘PHPNW’, ‘2011-10-08 09:00’, ‘Ramada Hotel’,
      ‘Awesome Conf!’)
Sunday, 9 October 11
Phabric
                       Inserting Relational Data
Scenario:
    Given the following sessions exist
    | Session Code | name                  | time | description      |
    | BDD          | BDD with behat        | 12:50 | TDD is cool!    |
    | CI           | Continous Integration | 13:30 | Integrate this! |
    And the following attendees exist
    | name                  |
    | Jack The Lad          |
    | Simple Simon          |
    | Peter Pan             |
    And the following votes exist
    | Attendee     | Session Code | Vote |
    | Jack The Lad | BDD          | UP   |
    | Simple Simon | BDD          | UP   |
    | Peter Pan    | BDD          | UP   |


Sunday, 9 October 11
Back To Our Problem At Sky




Sunday, 9 October 11
Balance.




Sunday, 9 October 11
A whole world of trouble.




Sunday, 9 October 11
Questions?




Sunday, 9 October 11
Links
     Behat Github Page: https://github.com/Behat/Behat

        Mink On Github: https://github.com/Behat/Mink

                       Website: http://behat.org/

       Phabric On Github: https://github.com/benwaine/
                            Phabric


                joind.in: http://joind.in/3592
Sunday, 9 October 11

Weitere ähnliche Inhalte

Was ist angesagt?

Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011Puppet
 
Puppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachPuppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachAlessandro Franceschi
 
Apache FTP Server Integration
Apache FTP Server IntegrationApache FTP Server Integration
Apache FTP Server IntegrationWO Community
 
Can you upgrade to Puppet 4.x?
Can you upgrade to Puppet 4.x?Can you upgrade to Puppet 4.x?
Can you upgrade to Puppet 4.x?Martin Alfke
 
Doing It Wrong with Puppet -
Doing It Wrong with Puppet - Doing It Wrong with Puppet -
Doing It Wrong with Puppet - Puppet
 
Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4ripienaar
 
Debootstrapが何をしているか
Debootstrapが何をしているかDebootstrapが何をしているか
Debootstrapが何をしているかterasakak
 
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is FineForward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is FineChris Adamson
 

Was ist angesagt? (12)

Puppi. Puppet strings to the shell
Puppi. Puppet strings to the shellPuppi. Puppet strings to the shell
Puppi. Puppet strings to the shell
 
Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011
 
ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!
 
Puppet modules: An Holistic Approach
Puppet modules: An Holistic ApproachPuppet modules: An Holistic Approach
Puppet modules: An Holistic Approach
 
Apache FTP Server Integration
Apache FTP Server IntegrationApache FTP Server Integration
Apache FTP Server Integration
 
Can you upgrade to Puppet 4.x?
Can you upgrade to Puppet 4.x?Can you upgrade to Puppet 4.x?
Can you upgrade to Puppet 4.x?
 
Doing It Wrong with Puppet -
Doing It Wrong with Puppet - Doing It Wrong with Puppet -
Doing It Wrong with Puppet -
 
Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4
 
Debootstrapが何をしているか
Debootstrapが何をしているかDebootstrapが何をしているか
Debootstrapが何をしているか
 
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is FineForward Swift 2017: Media Frameworks and Swift: This Is Fine
Forward Swift 2017: Media Frameworks and Swift: This Is Fine
 
John's Top PECL Picks
John's Top PECL PicksJohn's Top PECL Picks
John's Top PECL Picks
 
Smoking docker
Smoking dockerSmoking docker
Smoking docker
 

Andere mochten auch

Testing & Integration (The Remix)
 Testing & Integration (The Remix) Testing & Integration (The Remix)
Testing & Integration (The Remix)Ines Sombra
 
Exploratory Testing As A Quest
Exploratory Testing As A QuestExploratory Testing As A Quest
Exploratory Testing As A QuestChrishoneybee
 
Continuous Integration Testing in Django
Continuous Integration Testing in DjangoContinuous Integration Testing in Django
Continuous Integration Testing in DjangoKevin Harvey
 
Integration Testing Practice using Perl
Integration Testing Practice using PerlIntegration Testing Practice using Perl
Integration Testing Practice using PerlMasaki Nakagawa
 
What is this exploratory testing thing
What is this exploratory testing thingWhat is this exploratory testing thing
What is this exploratory testing thingtonybruce
 
Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
 Tips for Writing Better Charters for Exploratory Testing Sessions by Michael... Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...TEST Huddle
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration TestingDavid Berliner
 

Andere mochten auch (8)

Testing & Integration (The Remix)
 Testing & Integration (The Remix) Testing & Integration (The Remix)
Testing & Integration (The Remix)
 
Exploratory Testing As A Quest
Exploratory Testing As A QuestExploratory Testing As A Quest
Exploratory Testing As A Quest
 
Continuous Integration Testing in Django
Continuous Integration Testing in DjangoContinuous Integration Testing in Django
Continuous Integration Testing in Django
 
Integration Testing Practice using Perl
Integration Testing Practice using PerlIntegration Testing Practice using Perl
Integration Testing Practice using Perl
 
A Taste of Exploratory Testing
A Taste of Exploratory TestingA Taste of Exploratory Testing
A Taste of Exploratory Testing
 
What is this exploratory testing thing
What is this exploratory testing thingWhat is this exploratory testing thing
What is this exploratory testing thing
 
Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
 Tips for Writing Better Charters for Exploratory Testing Sessions by Michael... Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
Tips for Writing Better Charters for Exploratory Testing Sessions by Michael...
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 

Ähnlich wie Acceptance & Integration Testing With Behat (PHPNw2011)

De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresNorman Clarke
 
Puppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet
 
Rcos presentation
Rcos presentationRcos presentation
Rcos presentationmskmoorthy
 
The Not Java That's Not Scala
The Not Java That's Not ScalaThe Not Java That's Not Scala
The Not Java That's Not ScalaJustin Lee
 
Connfu Adhearsion
Connfu AdhearsionConnfu Adhearsion
Connfu AdhearsionBlueVia
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHPConFoo
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSCaridy Patino
 
Big app design for Node.js
Big app design for Node.jsBig app design for Node.js
Big app design for Node.jsSergi Mansilla
 
Apache Flume NG
Apache Flume NGApache Flume NG
Apache Flume NGhuguk
 
How To Build A Web Service
How To Build A Web ServiceHow To Build A Web Service
How To Build A Web ServiceMoses Ngone
 
Tackling Big Data with Hadoop
Tackling Big Data with HadoopTackling Big Data with Hadoop
Tackling Big Data with Hadooppoorlytrainedape
 
[Hands-on] Kubernetes | Nov 18, 2017
[Hands-on] Kubernetes | Nov 18, 2017[Hands-on] Kubernetes | Nov 18, 2017
[Hands-on] Kubernetes | Nov 18, 2017Oracle Korea
 
Parser combinators
Parser combinatorsParser combinators
Parser combinatorslifecoder
 
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en NeosTYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en NeosTYPO3 Nederland
 
eZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & ArchitectureeZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & ArchitectureAndré Rømcke
 
TripCase Unit Testing with Jasmine
TripCase Unit Testing with JasmineTripCase Unit Testing with Jasmine
TripCase Unit Testing with JasmineStephen Pond
 

Ähnlich wie Acceptance & Integration Testing With Behat (PHPNw2011) (20)

De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored procedures
 
Puppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet Design
 
Rcos presentation
Rcos presentationRcos presentation
Rcos presentation
 
The Not Java That's Not Scala
The Not Java That's Not ScalaThe Not Java That's Not Scala
The Not Java That's Not Scala
 
Connfu Adhearsion
Connfu AdhearsionConnfu Adhearsion
Connfu Adhearsion
 
Connfu adhearsion
Connfu adhearsionConnfu adhearsion
Connfu adhearsion
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHP
 
Caridy patino - node-js
Caridy patino - node-jsCaridy patino - node-js
Caridy patino - node-js
 
Conquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JSConquistando el Servidor con Node.JS
Conquistando el Servidor con Node.JS
 
Big app design for Node.js
Big app design for Node.jsBig app design for Node.js
Big app design for Node.js
 
Vertx
VertxVertx
Vertx
 
Apache Flume NG
Apache Flume NGApache Flume NG
Apache Flume NG
 
How To Build A Web Service
How To Build A Web ServiceHow To Build A Web Service
How To Build A Web Service
 
Tackling Big Data with Hadoop
Tackling Big Data with HadoopTackling Big Data with Hadoop
Tackling Big Data with Hadoop
 
[Hands-on] Kubernetes | Nov 18, 2017
[Hands-on] Kubernetes | Nov 18, 2017[Hands-on] Kubernetes | Nov 18, 2017
[Hands-on] Kubernetes | Nov 18, 2017
 
Parser combinators
Parser combinatorsParser combinators
Parser combinators
 
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en NeosTYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
TYPO3 Congres 2012 - Test-Driven Development binnen TYPO3 Flow en Neos
 
CloudInit Introduction
CloudInit IntroductionCloudInit Introduction
CloudInit Introduction
 
eZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & ArchitectureeZ publish 5[-alpha1] Introduction & Architecture
eZ publish 5[-alpha1] Introduction & Architecture
 
TripCase Unit Testing with Jasmine
TripCase Unit Testing with JasmineTripCase Unit Testing with Jasmine
TripCase Unit Testing with Jasmine
 

Mehr von benwaine

DPC 2016 - 53 Minutes or Less - Architecting For Failure
DPC 2016 - 53 Minutes or Less - Architecting For FailureDPC 2016 - 53 Minutes or Less - Architecting For Failure
DPC 2016 - 53 Minutes or Less - Architecting For Failurebenwaine
 
The Road To Technical Team Lead
The Road To Technical Team LeadThe Road To Technical Team Lead
The Road To Technical Team Leadbenwaine
 
PHPNW14 - Getting Started With AWS
PHPNW14 - Getting Started With AWSPHPNW14 - Getting Started With AWS
PHPNW14 - Getting Started With AWSbenwaine
 
Application Logging With The ELK Stack
Application Logging With The ELK StackApplication Logging With The ELK Stack
Application Logging With The ELK Stackbenwaine
 
Application Logging With Logstash
Application Logging With LogstashApplication Logging With Logstash
Application Logging With Logstashbenwaine
 
Business selectors
Business selectorsBusiness selectors
Business selectorsbenwaine
 
The Art Of Application Logging PHPNW12
The Art Of Application Logging PHPNW12The Art Of Application Logging PHPNW12
The Art Of Application Logging PHPNW12benwaine
 
Behat dpc12
Behat dpc12Behat dpc12
Behat dpc12benwaine
 
Say no to var_dump
Say no to var_dumpSay no to var_dump
Say no to var_dumpbenwaine
 

Mehr von benwaine (9)

DPC 2016 - 53 Minutes or Less - Architecting For Failure
DPC 2016 - 53 Minutes or Less - Architecting For FailureDPC 2016 - 53 Minutes or Less - Architecting For Failure
DPC 2016 - 53 Minutes or Less - Architecting For Failure
 
The Road To Technical Team Lead
The Road To Technical Team LeadThe Road To Technical Team Lead
The Road To Technical Team Lead
 
PHPNW14 - Getting Started With AWS
PHPNW14 - Getting Started With AWSPHPNW14 - Getting Started With AWS
PHPNW14 - Getting Started With AWS
 
Application Logging With The ELK Stack
Application Logging With The ELK StackApplication Logging With The ELK Stack
Application Logging With The ELK Stack
 
Application Logging With Logstash
Application Logging With LogstashApplication Logging With Logstash
Application Logging With Logstash
 
Business selectors
Business selectorsBusiness selectors
Business selectors
 
The Art Of Application Logging PHPNW12
The Art Of Application Logging PHPNW12The Art Of Application Logging PHPNW12
The Art Of Application Logging PHPNW12
 
Behat dpc12
Behat dpc12Behat dpc12
Behat dpc12
 
Say no to var_dump
Say no to var_dumpSay no to var_dump
Say no to var_dump
 

Kürzlich hochgeladen

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Kürzlich hochgeladen (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

Acceptance & Integration Testing With Behat (PHPNw2011)

  • 1. Acceptance & Integration Testing Using Behat Ben Waine Email: ben@ben-waine.co.uk Twitter: @bwaine Sunday, 9 October 11
  • 2. Roadmap •Intro To Behaviour Driven Development •Problems We Are Trying to solve at Sky With BDD •Behat •API Testing with Behat •UI Testing with Behat •Data Driven Testing •Is Behat solving our problem? Sunday, 9 October 11
  • 3. Me Software Engineer PHP Developer Sky Bet PHP / MySQL Stack PHPUnit / Selenium / Behat Sunday, 9 October 11
  • 4. Behaviour Driven Development (BDD) Sunday, 9 October 11
  • 5. Behaviour-driven development (BDD) takes the position that you can turn an idea for a requirement into implemented, tested, production-ready code simply and effectively, as long as .... everyone knows what’s going on. - Dan North Sunday, 9 October 11
  • 6. Writing tests first in a customer friendly language - Drinkwater et al 2011 Sunday, 9 October 11
  • 8. The Business Analyst Sunday, 9 October 11
  • 9. The Tester Sunday, 9 October 11
  • 10. The Developer Sunday, 9 October 11
  • 11. The Problem Sunday, 9 October 11
  • 14. What Does It Test? Scripts API’s Web Pages Models Sunday, 9 October 11
  • 15. Integration Testing != Unit Testing Sunday, 9 October 11
  • 16. Anatomy Of A Behat Test Sunday, 9 October 11
  • 19. My Amazing PHP Conference Website! Sunday, 9 October 11
  • 20. Writing Behat Tests $ben > cd /path/to/projects/tests $ben > behat --init Sunday, 9 October 11
  • 22. Feature Files Feature: Home Page When visiting the PHPCon site As a site visitor I need to be able to see what ` conferences are coming up Sunday, 9 October 11
  • 23. Scenarios Scenario: Get all conferences Given there is conference data in the database When I go to the homepage Then I should see three conferences in a table Sunday, 9 October 11
  • 24. Scenarios Given (Some Context) When (Some Event) Then (The Outcome) Sunday, 9 October 11
  • 25. Given (Some Context) Given there is conference data in the database Sunday, 9 October 11
  • 26. When (Some Event) When I go to the homepage When I use the findConferences method When I am on "/index.php" When I fill in "search-text" with "PHP" Sunday, 9 October 11
  • 27. Then (The Outcome) Then I should see three conferences in a table Then I should get a array of three conferences Then I should see "PHPNW" Sunday, 9 October 11
  • 28. ConferenceService.feature Feature: ConferenceService Class In order to display conferences on PHPCon site As a developer I need to be able to retrieve conferences Scenario: Get all conferences Given there is conference data in the database When I use the findConferences method Then I should get a array of three conferences AND it should contain the conference “PHPNW” Sunday, 9 October 11
  • 29. Class Methods & Annotations Sunday, 9 October 11
  • 30. / Everybody Stand Back / Behat Knows Regular Expressions Sunday, 9 October 11
  • 35. Copy and paste these methods into FeatureContext.php Sunday, 9 October 11
  • 38. Fill in the Feature Context File public function __construct(array $parameters) { $params = array( 'user' => $parameters['database']['username'], 'password' => $parameters['database']['password'], 'driver' => $parameters['database']['driver'], 'path' => $parameters['database']['dbPath'], ); $con = DoctrineDBALDriverManager::getConnection($params); $confMapper = new PHPConConferenceMapper($con); $confService = new PHPConConferenceService($confMapper); $this->service = $confService; } Sunday, 9 October 11
  • 39. Fill in the Feature Context File /** * @Given /^there is conference data in the database$/ */ public function thereIsConferneceDataInTheDatabase() { $fileName = self::$dataDir . 'sample-conf-session-data.sql'; self::executeQueriesInFile($fileName); } Sunday, 9 October 11
  • 40. Fill in the Feature Context File /** * @When /^I use the findConferences method$/ */ public function iUseTheFindConferencesMethod() { $this->result = $this->service->findConferences(); } Sunday, 9 October 11
  • 41. Fill in the Feature Context File /** *@Then /^I should get an array of (d+) conferences$/ */ public function iShouldGetAnArrayOfConferences ($numberOfCons) { assertInternalType('array', $this->result); assertEquals($numberOfCons, count($this->result)); } Sunday, 9 October 11
  • 42. /** * @Then /^it should contain the * conference "([^"]*)"$/ */ public function itShouldContainTheConference ($confName) { $names = array(); foreach($this->result as $conf) { $names[$conf->getName()] = true; } if(!array_key_exists($confName, $names)) { throw new Exception("Conference " . $confName . " not found"); } } Sunday, 9 October 11
  • 43. Ready to run the tests again..... Sunday, 9 October 11
  • 47. Add some application code..... Sunday, 9 October 11
  • 52. What about the UI? Sunday, 9 October 11
  • 54. Mink Goutte Sahi Zombie.js Sunday, 9 October 11
  • 55. Extend Mink Context Includes predefined steps Use Bundled steps to create higher level abstractions. Sunday, 9 October 11
  • 56. Back To: My Amazing PHP Conference Website! Sunday, 9 October 11
  • 57. Example Using Minks Bundled Steps Scenario: View all conferences on the homepage Given there is conference data in the database When I am on "/index.php" Then I should see "PHPNW" in the ".conferences" element And I should see "PHPUK" in the ".conferences" element And I should see "PBC11" in the ".conferences" element Sunday, 9 October 11
  • 58. class FeatureContext public function __construct(array $parameters) { $this->useContext('subcontext_alias', new UIContext($parameters)); ! // REST OF FEATURE CONSTRUCTOR } # features/bootstrap/UIContext.php use BehatBehatContextClosuredContextInterface, BehatBehatContextBehatContext, BehatBehatExceptionPendingException; use BehatGherkinNodePyStringNode, BehatGherkinNodeTableNode; require_once 'mink/autoload.php'; class UIContext extends BehatMinkBehatContextMinkContext { } Sunday, 9 October 11
  • 63. Powerful Headless UI Testing Out The Box Sunday, 9 October 11
  • 64. Abstracting your scenario Scenario: View all conferences on the homepage Given there is conference data in the database When I am on the "home" page Then I should see "PHPNW" in the "conferences" table And I should see "PHPUK" in the "conferences" table And I should see "PBC11" in the "conferences" table Sunday, 9 October 11
  • 65. Mink Feature Context class UIContext extends BehatMinkBehatContext MinkContext { protected $pageList = array( "home" => '/index.php'); protected $elementList = array( "conferences table" => '.conferences'); Sunday, 9 October 11
  • 66. /** * @When /^I am on the "([^"]*)" page$/ */ public function iAmOnThePage($pageName) { if(!isset($this->pageList[$pageName])) { throw new Exception( 'Page Name: not in page list'); } $page = $this->pageList[$pageName]; return new When("I am on "$page""); } Sunday, 9 October 11
  • 67. /** * @Then /^I should see "([^"]*)" in the "([^"]*)"$/ */ public function iShouldSeeInThe($text, $element) { if(!isset($this->elementList[$element])) { throw new Exception( 'Element: ' . $element . ‘not in element list'); } $element = $this->elementList[$element]; return new Then("I should see "$text" in then "$element" element"); } Sunday, 9 October 11
  • 68. Javascript Testing with..... Sahi Sunday, 9 October 11
  • 69. Back To: My Amazing PHP Conference Website! Sunday, 9 October 11
  • 70. Example @javascript Scenario: Use autocomplete functionality to complete a input field Given there is conference data in the database When I am on the "home" page When I fill in "search-text" with "PHP" And I wait for the suggestion box to appear Then I should see "PHPNW" Sunday, 9 October 11
  • 71. Great Reuse @javascript Scenario: Use autocomplete functionality to complete a input field Given there is conference data in the database When I am on the "home" page When I fill in "search-text" with "PHP" And I wait for the suggestion box to appear Then I should see "PHPNW" Sunday, 9 October 11
  • 72. // In the UIContext class /** * @Given /^I wait for the suggestion box to appear$/ */ public function iWaitForTheSuggestionBoxToAppear() { $this->getSession()->wait(5000, "$('.suggestions-results').children().length > 0" ); } Sunday, 9 October 11
  • 75. SQL Fixture Sunday, 9 October 11
  • 77. Phabric Inserting Data From Gherkin Tables Scenario: Given The following events exist | Name | Date | Venue | Desc | | PHPNW | 2011-10-08 09:00 | Ramada Hotel | Awesome conf! | | PHPUK | 2012-02-27 09:00 | London Business Center | Quite good conf. | INSERT INTO event `Name`, `Date`, `Venue`, `Desc` VALUE (‘PHPNW’, ‘2011-10-08 09:00’, ‘Ramada Hotel’, ‘Awesome Conf!’) Sunday, 9 October 11
  • 78. Phabric Transforming Table Headings to DB col names Scenario: Given The following events exist | Name | Date | Venue | Desc | | PHPNW | 2011-10-08 09:00 | Ramada Hotel | Awesome conf! | | PHPUK | 2012-02-27 09:00 | London Business Center | Quite good conf. | INSERT INTO event `name`, `date`, `venue`, `description` VALUE (‘PHPNW’, ‘2011-10-08 09:00’, ‘Ramada Hotel’, ‘Awesome Conf!’) Sunday, 9 October 11
  • 79. Phabric Transforming Table data using user defined callbacks Scenario: Given The following events exist | Name | Date | Venue | Desc | | PHPNW | 08/10/2011 09:00 | Ramada Hotel | Awesome conf! | | PHPUK | 27/02/2012 09:00 | London Business Center | Quite good conf. | INSERT INTO event `name`, `date`, `venue`, `description` VALUE (‘PHPNW’, ‘2011-10-08 09:00’, ‘Ramada Hotel’, ‘Awesome Conf!’) Sunday, 9 October 11
  • 80. Phabric Inserting Relational Data Scenario: Given the following sessions exist | Session Code | name | time | description | | BDD | BDD with behat | 12:50 | TDD is cool! | | CI | Continous Integration | 13:30 | Integrate this! | And the following attendees exist | name | | Jack The Lad | | Simple Simon | | Peter Pan | And the following votes exist | Attendee | Session Code | Vote | | Jack The Lad | BDD | UP | | Simple Simon | BDD | UP | | Peter Pan | BDD | UP | Sunday, 9 October 11
  • 81. Back To Our Problem At Sky Sunday, 9 October 11
  • 83. A whole world of trouble. Sunday, 9 October 11
  • 85. Links Behat Github Page: https://github.com/Behat/Behat Mink On Github: https://github.com/Behat/Mink Website: http://behat.org/ Phabric On Github: https://github.com/benwaine/ Phabric joind.in: http://joind.in/3592 Sunday, 9 October 11