SlideShare a Scribd company logo
1 of 91
Download to read offline
Acceptance &
                           Integration
                          Testing Using
                              Behat
                                   Ben Waine
                           Email: ben@ben-waine.co.uk
                                Twitter: @bwaine


Saturday, 29 October 11
Pair Programming



                          Say hello to the person next to you....




Saturday, 29 October 11
Set Up



                          USB Stick




Saturday, 29 October 11
Set Up
                                  For instant set up:

            1) Copy code into a new vhost with the web root
                     pointing at the ‘public’ folder.

                              2) Uncomment line 13 in:
                  tests/acceptance/features/bootstrap/UIContext.php

                          3) Install Sahi from the misc folder.


Saturday, 29 October 11
Set Up
                                  Goto: tests/acceptance/

            If setting up today run the Behat command using
                                behat.phar
                      eg: php behat.phar --tags demo1


                          If you have previously set up, run the
                                      behat command
                                  eg: behat --tags demo1


Saturday, 29 October 11
Me
          Software Engineer
          PHP Developer



         Sky Bet
         PHP / MySQL Stack
         PHPUnit / Selenium / Behat



Saturday, 29 October 11
Roadmap
        •Intro To Behaviour Driven Development
        •Introducing Behat
        •Gherkin & Steps
        •API / Service Layer Testing
        •UI Testing
        •Phabric - Dynamic Fixture Creation


Saturday, 29 October 11
joind.in


                          http://joind.in/talk/view/4328




Saturday, 29 October 11
What Marco Said......




Saturday, 29 October 11
Stories




Saturday, 29 October 11
What is BDD?




Saturday, 29 October 11
Introducing Behat....




Saturday, 29 October 11
Resistance is futile.......
Saturday, 29 October 11




Origins in Rubys cucumber
What Does It Test?

                                Scripts
                                 API’s
                               Web Pages
                                Models




Saturday, 29 October 11
Integration Testing
                                   !=
                             Unit Testing



Saturday, 29 October 11
Anatomy Of A Behat Test




Saturday, 29 October 11
Saturday, 29 October 11


Describes the behaviour in a story
Human Readable
Samples Later
Saturday, 29 October 11


PHP that maps to lines of the gherkin.
Behat parses gherkin and runs the associated
steps.
Writing Behat Tests

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




Saturday, 29 October 11


Bootstrap Behat. Provides you with a structure
Writing Behat Tests




Saturday, 29 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




Saturday, 29 October 11


Name of test
Description of test
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




Saturday, 29 October 11


Scenario.
Multiple scenarios in a single feature file
Scenarios
                              Given
                          (Some Context)

                              When
                           (Some Event)

                              Then
                          (The Outcome)


Saturday, 29 October 11


Keywords.
Always follow the same formula
Given
                          (Some Context)
            Given there is conference data in the database




Saturday, 29 October 11


Sets up some state or context
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"




Saturday, 29 October 11


Executes whatever it is your testing.
A http call, a method invocation, a page load
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"




Saturday, 29 October 11


An assertion.
Has it worked?
Are we seeing what we expect to see.
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”




Saturday, 29 October 11


Written By our TESTERS - Fed In From BAs
How is this feature executed?
Each step is reusable!
MENTION PHP METHODS + ANNOTATIONS!!!!
Class Methods & Annotations




Saturday, 29 October 11


Written By our TESTERS - Fed In From BAs
How is this feature executed?
Each step is reusable!
MENTION PHP METHODS + ANNOTATIONS!!!!
/ Everybody Stand Back /
                Behat Knows Regular Expressions




Saturday, 29 October 11


PHP Annotations used to map steps to lines
Behat supplies regex.
Demo One


                          Behat’s - Regex Fu




Saturday, 29 October 11
Introducing.......
                          The Sample Domain




Saturday, 29 October 11
My Amazing PHP Conference
                     Website




Saturday, 29 October 11
Service Layers




Saturday, 29 October 11
Demo One




Saturday, 29 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;
          }



Saturday, 29 October 11


The Feature context file
- Ever feature gets a instance. Set up some
resources.
- Set up the object to test - similar to PHPUnit’s set
up method.
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);
        }




Saturday, 29 October 11


Remember - Given sets the state.
Loads an sql fixture to the DB.
Fill in the Feature Context File

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

           }




Saturday, 29 October 11


Remember - When executes the thing you want to
test.
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));
           }




Saturday, 29 October 11


Remember - This verifies the output
Also - identified a number. Passes the number into
the method.
/**
                   * @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");
                          }
                 }

Saturday, 29 October 11
Exceptions == Test Failures




Saturday, 29 October 11
Demo Two


                          Passing Behat Test




Saturday, 29 October 11
Exercise One



                          Testing a service layer with Behat.




Saturday, 29 October 11
Exercise One


                          Open the PDF in the misc folder.
                            Read through Section One.
                                  Start Coding :)




Saturday, 29 October 11
Failing Test




Saturday, 29 October 11

If exceptions are encountered .....
Passing Test!




Saturday, 29 October 11
What about the UI?




Saturday, 29 October 11

We’ve covered testing a service class. But how do you test the UI?
Mink




Saturday, 29 October 11

Part of the Behat Project.
A abstraction over a number of different browser testing tools.
Mink


                            Goutte           Sahi




                                 Zombie.js



Saturday, 29 October 11

Goutte - headless browser
Sahi - like selenium
Zombie.js -
Extend Mink Context

                          Includes predefined steps

                   Use Bundled steps to create
                    higher level abstractions.


Saturday, 29 October 11
Back To:
                 My Amazing PHP Conference
                         Website!



Saturday, 29 October 11


We need a UI to test
introducing.....
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




Saturday, 29 October 11

This is ok - but ties the feature to your implementation.
Link
                                FeatureContext.php
                                        to
                                  UIContext.php




Saturday, 29 October 11

This is ok - but ties the feature to your implementation.
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
              {

              }


Saturday, 29 October 11


1) Linking feature files
2) All steps included ‘out the box’
Demo Three


                          A Behat UI Test (Using Mink + Goutte)




Saturday, 29 October 11

This is ok - but ties the feature to your implementation.
Exercise Two


                          Testing the UI with Mink and
                          the headless browser Goutte.




Saturday, 29 October 11
Exercise Two


                          Open the PDF in the sources folder.
                             Read through Section Two.
                                   Start Coding :)




Saturday, 29 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”




Saturday, 29 October 11
Mink Feature Context

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




Saturday, 29 October 11


A simple abstraction that makes a map of pages >
urls and elements > css selectors.
Example of step delegation.
Now you never change the feature file. Just steps.
/**
              * @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"");
             }




Saturday, 29 October 11


A simple abstraction that makes a map of pages >
urls and elements > css selectors.
Example of step delegation.
Now you never change the feature file. Just steps.
/**
              * @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 the
 "$element" element");
     }




Saturday, 29 October 11


A simple abstraction that makes a map of pages >
urls and elements > css selectors.
Example of step delegation.
Now you never change the feature file. Just steps.
Demo Four


              A Behat UI Test (Using Mink + Goutte)
         UI implementation abstracted away from Gherkin.




Saturday, 29 October 11

This is ok - but ties the feature to your implementation.
Exercise Three


          Abstracting the UI implementation away from the
                              Gherkin.




Saturday, 29 October 11
Exercise Three


                          Open the PDF in the sources folder.
                            Read through Section Three.
                                   Start Coding :)




Saturday, 29 October 11
Javascript Testing with
                                   Sahi




Saturday, 29 October 11
Back To:
                 My Amazing PHP Conference
                         Website!



Saturday, 29 October 11


We need a UI to test
introducing.....
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"




Saturday, 29 October 11

Mention @tags
SO you need to test java script.
Headless browser isn’t suitable.
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"




Saturday, 29 October 11


These are supplied by Mink. Woohoo!
REUSE
// 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"
                                );
                           }




Saturday, 29 October 11


Get session - gets you mink
Wait,
Then execute jquery!
Demo Five


                              UI Testing With Sahi




Saturday, 29 October 11

This is ok - but ties the feature to your implementation.
Saturday, 29 October 11
Exercise Four



                          UI Testing With Sahi




Saturday, 29 October 11
Exercise Four


                          Open the PDF in the sources folder.
                             Read through Section Four.
                                   Start Coding :)




Saturday, 29 October 11
Data




Saturday, 29 October 11

How do you supply your data?
SQL Fixture




Saturday, 29 October 11

Can be difficult to maintain.
Hides Data in a fixture NOT in your scenarios.
Phabric




Saturday, 29 October 11
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. |




Saturday, 29 October 11
Demo Five


                          Dynamic fixture creation with Phabric.




Saturday, 29 October 11

This is ok - but ties the feature to your implementation.
Case Study:
                          Behat at Sky Bet




Saturday, 29 October 11


Whats the problem we are solving.
Three elements of the team.
Delivering the product first time. Correctly.
The Problem




Saturday, 29 October 11


Whats the problem we are solving.
Three elements of the team.
Delivering the product first time. Correctly.
The Business
          Analyst
Saturday, 29 October 11


BA / Product owner has all the knowledge
Write stories
The Tester




Saturday, 29 October 11


Testers test implementation vs the story
The
                                  Developer
Saturday, 29 October 11


Dev - write the code
Automate the process of testing if code meets the
requirements of a story
The Problem




Saturday, 29 October 11


Whats the problem we are solving.
Three elements of the team.
Delivering the product first time. Correctly.
BDD - Skybet Workflow

                                BA’s Write Stories

                              Testers Write Gherkin

                          Developers Write Steps + Code



Saturday, 29 October 11


Whats the problem we are solving.
Three elements of the team.
Delivering the product first time. Correctly.
BDD - Skybet Workflow


                                  Less Defects

                          Fewer times through this cycle




Saturday, 29 October 11


Whats the problem we are solving.
Three elements of the team.
Delivering the product first time. Correctly.
The Place Of Acceptance &
                        Integration Tests



Saturday, 29 October 11


Whats the problem we are solving.
Three elements of the team.
Delivering the product first time. Correctly.
Balance.




Saturday, 29 October 11

Jason Huggins
The place of acceptance and integration tests
A whole world of trouble.




Saturday, 29 October 11

Takes a long time to run,
Harder to implement, when they break you have to do this again!
not as reassuring!
joind.in


                          http://joind.in/talk/view/4328




Saturday, 29 October 11
Questions?




Saturday, 29 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




Saturday, 29 October 11

More Related Content

What's hot

Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011Puppet
 
Apache FTP Server Integration
Apache FTP Server IntegrationApache FTP Server Integration
Apache FTP Server IntegrationWO Community
 
Introduction to linux
Introduction to linuxIntroduction to linux
Introduction to linuxQIANG XU
 
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
 

What's hot (15)

Puppi. Puppet strings to the shell
Puppi. Puppet strings to the shellPuppi. Puppet strings to the shell
Puppi. Puppet strings to the shell
 
Anatomy of a reusable module
Anatomy of a reusable moduleAnatomy of a reusable module
Anatomy of a reusable module
 
Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011Oliver hookins puppetcamp2011
Oliver hookins puppetcamp2011
 
Apache FTP Server Integration
Apache FTP Server IntegrationApache FTP Server Integration
Apache FTP Server Integration
 
ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!ReUse Your (Puppet) Modules!
ReUse Your (Puppet) Modules!
 
DIWE - File handling with PHP
DIWE - File handling with PHPDIWE - File handling with PHP
DIWE - File handling with PHP
 
Introduction to linux
Introduction to linuxIntroduction to linux
Introduction to linux
 
Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4Whirlwind Tour of Puppet 4
Whirlwind Tour of Puppet 4
 
Debootstrapが何をしているか
Debootstrapが何をしているかDebootstrapが何をしているか
Debootstrapが何をしているか
 
has("builds")
has("builds")has("builds")
has("builds")
 
John's Top PECL Picks
John's Top PECL PicksJohn's Top PECL Picks
John's Top PECL Picks
 
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
 
dojo.things()
dojo.things()dojo.things()
dojo.things()
 
Intro to-puppet
Intro to-puppetIntro to-puppet
Intro to-puppet
 
Power of Puppet 4
Power of Puppet 4Power of Puppet 4
Power of Puppet 4
 

Viewers also liked

[BDD] Introduction to Behat (PL)
[BDD] Introduction to Behat (PL)[BDD] Introduction to Behat (PL)
[BDD] Introduction to Behat (PL)Piotr Pelczar
 
I put on my mink and wizard behat (tutorial)
I put on my mink and wizard behat (tutorial)I put on my mink and wizard behat (tutorial)
I put on my mink and wizard behat (tutorial)xsist10
 
Behat - Beyond the Basics (2016 - SunshinePHP)
Behat - Beyond the Basics (2016 - SunshinePHP)Behat - Beyond the Basics (2016 - SunshinePHP)
Behat - Beyond the Basics (2016 - SunshinePHP)Jessica Mauerhan
 
Web Acceptance Testing with Behat
Web Acceptance Testing with BehatWeb Acceptance Testing with Behat
Web Acceptance Testing with BehatFabian Kiss
 
Behat bdd training (php) course slides pdf
Behat bdd training (php) course slides pdfBehat bdd training (php) course slides pdf
Behat bdd training (php) course slides pdfseleniumbootcamp
 

Viewers also liked (6)

[BDD] Introduction to Behat (PL)
[BDD] Introduction to Behat (PL)[BDD] Introduction to Behat (PL)
[BDD] Introduction to Behat (PL)
 
I put on my mink and wizard behat (tutorial)
I put on my mink and wizard behat (tutorial)I put on my mink and wizard behat (tutorial)
I put on my mink and wizard behat (tutorial)
 
Behat - Beyond the Basics (2016 - SunshinePHP)
Behat - Beyond the Basics (2016 - SunshinePHP)Behat - Beyond the Basics (2016 - SunshinePHP)
Behat - Beyond the Basics (2016 - SunshinePHP)
 
Web Acceptance Testing with Behat
Web Acceptance Testing with BehatWeb Acceptance Testing with Behat
Web Acceptance Testing with Behat
 
Behat bdd training (php) course slides pdf
Behat bdd training (php) course slides pdfBehat bdd training (php) course slides pdf
Behat bdd training (php) course slides pdf
 
Behat 3.0 meetup (March)
Behat 3.0 meetup (March)Behat 3.0 meetup (March)
Behat 3.0 meetup (March)
 

Similar to Acceptance & Integration Testing With Behat (PBC11)

BDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpecBDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpecMarcello Duarte
 
Fabric-让部署变得简单
Fabric-让部署变得简单Fabric-让部署变得简单
Fabric-让部署变得简单Eric Lo
 
How to Install, Use, and Customize Drush
How to Install, Use, and Customize DrushHow to Install, Use, and Customize Drush
How to Install, Use, and Customize DrushAcquia
 
Concurrency
ConcurrencyConcurrency
Concurrencyehuard
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with PuppetAlessandro Franceschi
 
Batou - multi-(host|component|environment|version|platform) deployment
Batou - multi-(host|component|environment|version|platform) deploymentBatou - multi-(host|component|environment|version|platform) deployment
Batou - multi-(host|component|environment|version|platform) deploymentChristian Theune
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxNick Belhomme
 
Devon 2011-f-4-improve your-javascript
Devon 2011-f-4-improve your-javascriptDevon 2011-f-4-improve your-javascript
Devon 2011-f-4-improve your-javascriptDaum DNA
 
Best Practices in Ext GWT
Best Practices in Ext GWTBest Practices in Ext GWT
Best Practices in Ext GWTSencha
 
Scalable Systems Management with Puppet
Scalable Systems Management with PuppetScalable Systems Management with Puppet
Scalable Systems Management with PuppetPuppet
 
Scalable systems management with puppet
Scalable systems management with puppetScalable systems management with puppet
Scalable systems management with puppetPuppet
 
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
 
One man loves powershell once he failed
One man loves powershell once he failedOne man loves powershell once he failed
One man loves powershell once he failedKazuhiro Matsushima
 
Scaling websites with RabbitMQ A(rlvaro Videla)
Scaling websites with RabbitMQ   A(rlvaro Videla)Scaling websites with RabbitMQ   A(rlvaro Videla)
Scaling websites with RabbitMQ A(rlvaro Videla)Ontico
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudyYusuke Ando
 
Java 7 Features and Enhancements
Java 7 Features and EnhancementsJava 7 Features and Enhancements
Java 7 Features and EnhancementsGagan Agrawal
 

Similar to Acceptance & Integration Testing With Behat (PBC11) (20)

BDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpecBDD For Zend Framework With PHPSpec
BDD For Zend Framework With PHPSpec
 
Fabric-让部署变得简单
Fabric-让部署变得简单Fabric-让部署变得简单
Fabric-让部署变得简单
 
Distribute the workload, PHP Barcelona 2011
Distribute the workload, PHP Barcelona 2011Distribute the workload, PHP Barcelona 2011
Distribute the workload, PHP Barcelona 2011
 
How to Install, Use, and Customize Drush
How to Install, Use, and Customize DrushHow to Install, Use, and Customize Drush
How to Install, Use, and Customize Drush
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with Puppet
 
Batou - multi-(host|component|environment|version|platform) deployment
Batou - multi-(host|component|environment|version|platform) deploymentBatou - multi-(host|component|environment|version|platform) deployment
Batou - multi-(host|component|environment|version|platform) deployment
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBenelux
 
Puppet_training
Puppet_trainingPuppet_training
Puppet_training
 
Devon 2011-f-4-improve your-javascript
Devon 2011-f-4-improve your-javascriptDevon 2011-f-4-improve your-javascript
Devon 2011-f-4-improve your-javascript
 
Best Practices in Ext GWT
Best Practices in Ext GWTBest Practices in Ext GWT
Best Practices in Ext GWT
 
Scalable Systems Management with Puppet
Scalable Systems Management with PuppetScalable Systems Management with Puppet
Scalable Systems Management with Puppet
 
Scalable systems management with puppet
Scalable systems management with puppetScalable systems management with puppet
Scalable systems management with puppet
 
Infrastructure as Code with Chef / Puppet
Infrastructure as Code with Chef / PuppetInfrastructure as Code with Chef / Puppet
Infrastructure as Code with Chef / Puppet
 
Modern Python Testing
Modern Python TestingModern Python Testing
Modern Python Testing
 
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
 
One man loves powershell once he failed
One man loves powershell once he failedOne man loves powershell once he failed
One man loves powershell once he failed
 
Scaling websites with RabbitMQ A(rlvaro Videla)
Scaling websites with RabbitMQ   A(rlvaro Videla)Scaling websites with RabbitMQ   A(rlvaro Videla)
Scaling websites with RabbitMQ A(rlvaro Videla)
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
 
Java 7 Features and Enhancements
Java 7 Features and EnhancementsJava 7 Features and Enhancements
Java 7 Features and Enhancements
 

More from 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
 

More from 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
 

Recently uploaded

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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 

Recently uploaded (20)

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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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)
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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 (PBC11)

  • 1. Acceptance & Integration Testing Using Behat Ben Waine Email: ben@ben-waine.co.uk Twitter: @bwaine Saturday, 29 October 11
  • 2. Pair Programming Say hello to the person next to you.... Saturday, 29 October 11
  • 3. Set Up USB Stick Saturday, 29 October 11
  • 4. Set Up For instant set up: 1) Copy code into a new vhost with the web root pointing at the ‘public’ folder. 2) Uncomment line 13 in: tests/acceptance/features/bootstrap/UIContext.php 3) Install Sahi from the misc folder. Saturday, 29 October 11
  • 5. Set Up Goto: tests/acceptance/ If setting up today run the Behat command using behat.phar eg: php behat.phar --tags demo1 If you have previously set up, run the behat command eg: behat --tags demo1 Saturday, 29 October 11
  • 6. Me Software Engineer PHP Developer Sky Bet PHP / MySQL Stack PHPUnit / Selenium / Behat Saturday, 29 October 11
  • 7. Roadmap •Intro To Behaviour Driven Development •Introducing Behat •Gherkin & Steps •API / Service Layer Testing •UI Testing •Phabric - Dynamic Fixture Creation Saturday, 29 October 11
  • 8. joind.in http://joind.in/talk/view/4328 Saturday, 29 October 11
  • 11. What is BDD? Saturday, 29 October 11
  • 13. Resistance is futile....... Saturday, 29 October 11 Origins in Rubys cucumber
  • 14. What Does It Test? Scripts API’s Web Pages Models Saturday, 29 October 11
  • 15. Integration Testing != Unit Testing Saturday, 29 October 11
  • 16. Anatomy Of A Behat Test Saturday, 29 October 11
  • 17. Saturday, 29 October 11 Describes the behaviour in a story Human Readable Samples Later
  • 18. Saturday, 29 October 11 PHP that maps to lines of the gherkin. Behat parses gherkin and runs the associated steps.
  • 19. Writing Behat Tests $ben > cd /path/to/projects/tests $ben > behat --init Saturday, 29 October 11 Bootstrap Behat. Provides you with a structure
  • 21. 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 Saturday, 29 October 11 Name of test Description of test
  • 22. 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 Saturday, 29 October 11 Scenario. Multiple scenarios in a single feature file
  • 23. Scenarios Given (Some Context) When (Some Event) Then (The Outcome) Saturday, 29 October 11 Keywords. Always follow the same formula
  • 24. Given (Some Context) Given there is conference data in the database Saturday, 29 October 11 Sets up some state or context
  • 25. 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" Saturday, 29 October 11 Executes whatever it is your testing. A http call, a method invocation, a page load
  • 26. 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" Saturday, 29 October 11 An assertion. Has it worked? Are we seeing what we expect to see.
  • 27. 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” Saturday, 29 October 11 Written By our TESTERS - Fed In From BAs How is this feature executed? Each step is reusable! MENTION PHP METHODS + ANNOTATIONS!!!!
  • 28. Class Methods & Annotations Saturday, 29 October 11 Written By our TESTERS - Fed In From BAs How is this feature executed? Each step is reusable! MENTION PHP METHODS + ANNOTATIONS!!!!
  • 29. / Everybody Stand Back / Behat Knows Regular Expressions Saturday, 29 October 11 PHP Annotations used to map steps to lines Behat supplies regex.
  • 30. Demo One Behat’s - Regex Fu Saturday, 29 October 11
  • 31. Introducing....... The Sample Domain Saturday, 29 October 11
  • 32. My Amazing PHP Conference Website Saturday, 29 October 11
  • 34. Demo One Saturday, 29 October 11
  • 35. 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; } Saturday, 29 October 11 The Feature context file - Ever feature gets a instance. Set up some resources. - Set up the object to test - similar to PHPUnit’s set up method.
  • 36. 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); } Saturday, 29 October 11 Remember - Given sets the state. Loads an sql fixture to the DB.
  • 37. Fill in the Feature Context File /** * @When /^I use the findConferences method$/ */ public function iUseTheFindConferencesMethod() { $this->result = $this->service->findConferences(); } Saturday, 29 October 11 Remember - When executes the thing you want to test.
  • 38. 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)); } Saturday, 29 October 11 Remember - This verifies the output Also - identified a number. Passes the number into the method.
  • 39. /** * @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"); } } Saturday, 29 October 11
  • 40. Exceptions == Test Failures Saturday, 29 October 11
  • 41. Demo Two Passing Behat Test Saturday, 29 October 11
  • 42. Exercise One Testing a service layer with Behat. Saturday, 29 October 11
  • 43. Exercise One Open the PDF in the misc folder. Read through Section One. Start Coding :) Saturday, 29 October 11
  • 44. Failing Test Saturday, 29 October 11 If exceptions are encountered .....
  • 46. What about the UI? Saturday, 29 October 11 We’ve covered testing a service class. But how do you test the UI?
  • 47. Mink Saturday, 29 October 11 Part of the Behat Project. A abstraction over a number of different browser testing tools.
  • 48. Mink Goutte Sahi Zombie.js Saturday, 29 October 11 Goutte - headless browser Sahi - like selenium Zombie.js -
  • 49. Extend Mink Context Includes predefined steps Use Bundled steps to create higher level abstractions. Saturday, 29 October 11
  • 50. Back To: My Amazing PHP Conference Website! Saturday, 29 October 11 We need a UI to test introducing.....
  • 51. 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 Saturday, 29 October 11 This is ok - but ties the feature to your implementation.
  • 52. Link FeatureContext.php to UIContext.php Saturday, 29 October 11 This is ok - but ties the feature to your implementation.
  • 53. 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 { } Saturday, 29 October 11 1) Linking feature files 2) All steps included ‘out the box’
  • 54. Demo Three A Behat UI Test (Using Mink + Goutte) Saturday, 29 October 11 This is ok - but ties the feature to your implementation.
  • 55. Exercise Two Testing the UI with Mink and the headless browser Goutte. Saturday, 29 October 11
  • 56. Exercise Two Open the PDF in the sources folder. Read through Section Two. Start Coding :) Saturday, 29 October 11
  • 57. 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” Saturday, 29 October 11
  • 58. Mink Feature Context class UIContext extends BehatMinkBehatContext MinkContext { protected $pageList = array( "home" => '/index.php'); protected $elementList = array( "conferences table" => '.conferences'); Saturday, 29 October 11 A simple abstraction that makes a map of pages > urls and elements > css selectors. Example of step delegation. Now you never change the feature file. Just steps.
  • 59. /** * @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""); } Saturday, 29 October 11 A simple abstraction that makes a map of pages > urls and elements > css selectors. Example of step delegation. Now you never change the feature file. Just steps.
  • 60. /** * @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 the "$element" element"); } Saturday, 29 October 11 A simple abstraction that makes a map of pages > urls and elements > css selectors. Example of step delegation. Now you never change the feature file. Just steps.
  • 61. Demo Four A Behat UI Test (Using Mink + Goutte) UI implementation abstracted away from Gherkin. Saturday, 29 October 11 This is ok - but ties the feature to your implementation.
  • 62. Exercise Three Abstracting the UI implementation away from the Gherkin. Saturday, 29 October 11
  • 63. Exercise Three Open the PDF in the sources folder. Read through Section Three. Start Coding :) Saturday, 29 October 11
  • 64. Javascript Testing with Sahi Saturday, 29 October 11
  • 65. Back To: My Amazing PHP Conference Website! Saturday, 29 October 11 We need a UI to test introducing.....
  • 66. 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" Saturday, 29 October 11 Mention @tags SO you need to test java script. Headless browser isn’t suitable.
  • 67. 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" Saturday, 29 October 11 These are supplied by Mink. Woohoo! REUSE
  • 68. // 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" ); } Saturday, 29 October 11 Get session - gets you mink Wait, Then execute jquery!
  • 69. Demo Five UI Testing With Sahi Saturday, 29 October 11 This is ok - but ties the feature to your implementation.
  • 71. Exercise Four UI Testing With Sahi Saturday, 29 October 11
  • 72. Exercise Four Open the PDF in the sources folder. Read through Section Four. Start Coding :) Saturday, 29 October 11
  • 73. Data Saturday, 29 October 11 How do you supply your data?
  • 74. SQL Fixture Saturday, 29 October 11 Can be difficult to maintain. Hides Data in a fixture NOT in your scenarios.
  • 76. 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. | Saturday, 29 October 11
  • 77. Demo Five Dynamic fixture creation with Phabric. Saturday, 29 October 11 This is ok - but ties the feature to your implementation.
  • 78. Case Study: Behat at Sky Bet Saturday, 29 October 11 Whats the problem we are solving. Three elements of the team. Delivering the product first time. Correctly.
  • 79. The Problem Saturday, 29 October 11 Whats the problem we are solving. Three elements of the team. Delivering the product first time. Correctly.
  • 80. The Business Analyst Saturday, 29 October 11 BA / Product owner has all the knowledge Write stories
  • 81. The Tester Saturday, 29 October 11 Testers test implementation vs the story
  • 82. The Developer Saturday, 29 October 11 Dev - write the code Automate the process of testing if code meets the requirements of a story
  • 83. The Problem Saturday, 29 October 11 Whats the problem we are solving. Three elements of the team. Delivering the product first time. Correctly.
  • 84. BDD - Skybet Workflow BA’s Write Stories Testers Write Gherkin Developers Write Steps + Code Saturday, 29 October 11 Whats the problem we are solving. Three elements of the team. Delivering the product first time. Correctly.
  • 85. BDD - Skybet Workflow Less Defects Fewer times through this cycle Saturday, 29 October 11 Whats the problem we are solving. Three elements of the team. Delivering the product first time. Correctly.
  • 86. The Place Of Acceptance & Integration Tests Saturday, 29 October 11 Whats the problem we are solving. Three elements of the team. Delivering the product first time. Correctly.
  • 87. Balance. Saturday, 29 October 11 Jason Huggins The place of acceptance and integration tests
  • 88. A whole world of trouble. Saturday, 29 October 11 Takes a long time to run, Harder to implement, when they break you have to do this again! not as reassuring!
  • 89. joind.in http://joind.in/talk/view/4328 Saturday, 29 October 11
  • 91. 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 Saturday, 29 October 11