SlideShare ist ein Scribd-Unternehmen logo
1 von 98
Downloaden Sie, um offline zu lesen
ACCEPTANCE &
      INTEGRATION TESTING WITH
               BEHAT
                      DPC 2012 - Ben Waine - @bwaine

                            https://joind.in/6218




Thursday, 7 June 12
The Environment
                          Oracle Open Box
                            Ubuntu 12.12
                      Behat + Examples Installed

        1. Get Open Box and the VHD from the provided USB
                               stick.

                         2. Install Open Box

                          3. Load the VHD

Thursday, 7 June 12
Demo: The Environment




Thursday, 7 June 12
BEN WAINE
    • Freelance Software Engineer
    •Worked with Behat at Sky and
    IPC

    •DPC was the second
    conference I ever attended in
    2009. Glad to be back!

    •Twitter: @bwaine

Thursday, 7 June 12
Todays Roadmap
           1. Introduction to BDD and Behat
           2. How to Write Behat Tests
           3. Mink - UI Testing With Behat
           4. Mink - Javascript Testing
           5. Phabric - Fixture Building
           6. Behat - Common Contexts
           7. Case Study - Behat In The Wild
           8. Tips From The Trenches
           9. Questions



Thursday, 7 June 12
Todays Roadmap
           1. Introduction to BDD and Behat
           2. How to Write Behat Tests
           3. Mink - UI Testing With Behat
           4. Mink - Javascript Testing
           5. Phabric - Fixture Building
           6. Behat - Common Contexts
           7. Case Study - Behat In The Wild
           8. Tips From The Trenches
           9. Questions



Thursday, 7 June 12
My Questions




Thursday, 7 June 12
Behaviour Driven Development




Thursday, 7 June 12
Stories




Thursday, 7 June 12
Dan North - Whats In A Story?



                      http://dannorth.net/whats-in-a-story/
Thursday, 7 June 12
Dan North’s Recipe For A Story
                Title (one line describing the story)

                Narrative:
                As a [role]
                I want [feature]
                So that [benefit]

                Acceptance Criteria: (presented as Scenarios)

                Scenario 1: Title
                Given [context]
                  And [some more context]...
                When [event]
                Then [outcome]
                  And [another outcome]...


Thursday, 7 June 12
Behat
        ‘A open source behaviour driven development [testing]
                            framework’
                      ‘Inspired by Ruby’s Cucumber project’




Thursday, 7 June 12
Behat - What Can We Do With It?
                             Test Anything!



     Web Applications          Shell Scripts            Your
                                                    developers
                                                    relationship
                      Web Services    PHP Scripts       skills
Thursday, 7 June 12
Where Does Behat Sit In The BDD
         Ecosystem?

                        PHPSpec - Class Level BDD

                      Behat - Service / UI Level Testing




Thursday, 7 June 12
BDD == TDD??



                      http://dannorth.net/2012/05/31/bdd-is-like-tdd-if/
Thursday, 7 June 12
Behat - Installation So Easy I’m Not
           Even Covering It.

                      Composer          Pear


                                 Phar          Github

Thursday, 7 June 12
My Friend Shashi -
            http://lestbddphp.wordpress.com/2012/05/07/enjoy-
                          minkextension-for-behat/

            Great article on setting up Behat 2.4 (latest version)




Thursday, 7 June 12
Testing Unix’s famous ‘ls’ command
                            An Example From behat.org

                            1. In the VM open Sublime Text 2

                      2. cd /home/tuser/tutorial/01-LinuxCommands




Thursday, 7 June 12
Testing Unix’s famous ‘ls’ command
                         What does a behat test consist of?

                       1. Run: bin/behat features/ls.feature

                                2. Open features/ls.feature

                      3. Open features/bootstrap/FeatureContext.php




Thursday, 7 June 12
Gherkin




Thursday, 7 June 12
Testing Unix’s famous ‘ls’ command
                               features/ls.feature
        Feature: ls
          In order to see the directory structure
          As a UNIX user
          I need to be able to list the current directory's contents

             Scenario: List 2 files in a directory
               Given I am in a directory "test"
               And I have a file named "foo"
               And I have a file named "bar"
               When I run "ls"
               Then I should get:
                 """
                 bar
                 foo
                 """


                                             Source: http://docs.behat.org/quick_intro.html
Thursday, 7 June 12
Dan North’s Recipe For A Story
                Title (one line describing the story)

                Narrative:
                As a [role]
                I want [feature]
                So that [benefit]

                Acceptance Criteria: (presented as Scenarios)

                Scenario 1: Title
                Given [context]
                  And [some more context]...
                When [event]
                Then [outcome]
                  And [another outcome]...


Thursday, 7 June 12
Steps - Plain Old PHP




Thursday, 7 June 12
features/bootstrap/FeatureContext.php
 <?php

 use BehatBehatContextBehatContext,
     BehatBehatExceptionPendingException;
 use BehatGherkinNodePyStringNode,
     BehatGherkinNodeTableNode;

 class FeatureContext extends BehatContext
 {
     private $output;

           /** @Given /^I am in a directory "([^"]*)"$/ */
           public function iAmInADirectory($dir)
           {
               if (!file_exists($dir)) {
                   mkdir($dir);
               }
               chdir($dir);
           }


Source: http://docs.behat.org/quick_intro.html                1/2
Thursday, 7 June 12
features/bootstrap/FeatureContext.php
               /** @Given /^I have a file named "([^"]*)"$/ */
               public function iHaveAFileNamed($file)
               {
                   touch($file);
               }

               /** @When /^I run "([^"]*)"$/ */
               public function iRun($command)
               {
                   exec($command, $output);
                   $this->output = trim(implode("n", $output));
               }

               /** @Then /^I should get:$/ */
               public function iShouldGet(PyStringNode $string)
               {
                   if ((string) $string !== $this->output) {
                       throw new Exception(
                           "Actual output is:n" . $this->output
                       );
                   }
               }
                                                                   2/2
Thursday, 7 June 12
Testing Unix’s famous ‘ls’ command
                      What does a behat test consist of?

                         Feature Files & Feature Contexts

                                 Which contain:

                           Features / Stories and Steps




Thursday, 7 June 12
Behat Directory Structure




Thursday, 7 June 12
Exercise One: Hello World




Thursday, 7 June 12
Exercise One
       Write a php script which takes the users name as it’s only
                              argument.

               When executed it should write ‘Hello’ to the screen.

                                   eg. Hello Ben

                      If no name is given then it should output
                                   ‘Hello Stranger’


Thursday, 7 June 12
The BDD approach - write
          scenarios that define behaviour
                        first.



Thursday, 7 June 12
Setting Up A Project

                      1. cd /home/tuser/tutorial/02-HelloScript

                            2. run bin/behat --init




Thursday, 7 June 12
Behat Killer Feature - Write A Step
     Get The Regex For Free!



Thursday, 7 June 12
The BDD Workflow

                              1. Create features/hello.feature

                        2. Write a scenario to test the ‘hello’ script

                      3. Run bin/behat features/hello.feature

                        4. Copy the steps into features/bootstrap/
                                  FeatureContext.php


Thursday, 7 June 12
Clues
         1. The Command is in another directory. Change to that
                     directory in the given step?

                      2. When is an event or action

                         3. Then tests the event




Thursday, 7 June 12
The BDD Workflow

                              1. Create features/hello.feature

                        2. Write a scenario to test the ‘hello’ script

                      3. Run bin/behat features/hello.feature

                        4. Copy the steps into features/bootstrap/
                                  FeatureContext.php


Thursday, 7 June 12
The BDD Workflow
        5. Complete the methods in the FeatureContext.php file.

                      6. Run bin/behat features/hello.feature

                                        7. FAIL

                               8. Write the Hello Script.

                                        9. PASS


Thursday, 7 June 12
Dan North Revisited:
                      Making a Good Story
   The title should describe an activity
   The narrative should include a role, a feature and a benefit
   The scenario title should say what’s different
   The scenario should be described in terms of Givens, Events
   and Outcomes
   The givens should define all of, and no more than, the
   required context
   The event should describe the feature
   The story should be small enough to fit in an iteration
Thursday, 7 June 12
Time to share.




Thursday, 7 June 12
UI Testing With Behat & Mink




Thursday, 7 June 12
My Questions




Thursday, 7 June 12
Mink

            Goutte               Web Driver          Zombie Js


                      Selenium                Sahi

Thursday, 7 June 12
Mink - A UI Testing Tool Abstraction
      Headless Browser (Goutte)

      Makes HTTP calls and inspect the output
      Fast and lightweight
      Can’t test Javascipt / AJAX

      Browser Controller (Sahi / Selenium / WebDriver)

      Control a real browser
      Simulates user interaction with a web site
      Can test javascript / AJAX
      Slower than headless browser
Thursday, 7 June 12
Included With Mink
                                   A new context class to use

                          Bundled steps to test UI elements with. Eg:


                      Given I am on "/wiki/Main_Page"
                      When I fill in "search" with "Behavior Driven Development"
                      And I press "searchButton"
                      Then I should see "agile software development"




                                            Source: http://behat.org/cookbook/behat_and_mink.html

Thursday, 7 June 12
Using MinkContext
        If you have custom steps or an existing FeatureContext

                      <?php

                      class FeatureContext extends BehatContext
                      {
                          public function __construct(array $parameters)
                          {
                              $this->useContext(
                               'mink',
                               new BehatMinkExtensionContextMinkContext
                              );
                          }
                      }




Thursday, 7 June 12
Exercise Two:
                      Hello World On The Web



Thursday, 7 June 12
Exercise Two
                        Write a simple web page with a form.

                      The form should have a single field ‘name’.

             When typing in a name and pressing submit, the page
             should reload and print the message ‘Hello _name_’

                                    eg. Hello Ben

         On the page with the greeting a link with the text ‘again’
            should take you back to the original form page.
Thursday, 7 June 12
Setting Up A Project

                      1. cd /home/tuser/tutorial/03-HelloPage

                             2. run bin/behat --init

                      3. Web page goes in the ‘public’ directory

                         4. Add behat.yml to 03-HelloPage
                             See example misc/behat.yml


Thursday, 7 June 12
Using MinkContext
        If you have custom steps or an existing FeatureContext

                      <?php

                      class FeatureContext extends BehatContext
                      {
                          public function __construct(array $parameters)
                          {
                              $this->useContext(
                               'mink',
                               new BehatMinkExtensionContextMinkContext
                              );
                          }
                      }




Thursday, 7 June 12
Using MinkContext

   New in 2.4 - If Mink extension is installed and you have no
                   custom steps. It’s automatic!

                          Great for testers.




Thursday, 7 June 12
The BDD Workflow
                              1. Create features/hello.feature

                         2. Write a scenario to test the ‘hello’ page
                                  Use bundled Mink Steps

                                    3. Use MinkContext

                      4. Run bin/behat features/hello.feature
                                Wow no new steps required!


Thursday, 7 June 12
The BDD Workflow
                              5. FAIL

                         6. Write web page

                              7. PASS




Thursday, 7 June 12
Debugging Steps
                              Then /^print last response$/

                              Then /^show last response$/

                      ‘And I Wait’ - implement yourself with fgets



                      Lets try this on the test we have just written.


Thursday, 7 June 12
Testing Javascript Interactions




Thursday, 7 June 12
Tagging Tests For Javascript Testing
       Use tags to tell Mink to use a full browser rather than
                               Goutte.

                 @javascript
                 Scenario: As an attendee
                 I should be able to tag scenarios after reading this
                 Given I am testing javascript
                 When I read this slide
                 Then I'll tag scenarios with @javascript LIKE A BOSS




Thursday, 7 June 12
Steps To Use For Testing JS
              Custom steps which manipulate the mink session.

              /**
                * @Then /^I wait for the suggestion box to appear$/
                */
              public function iWaitForTheSuggestionBoxToAppear()
              {
                   $this->getSubcontext('mink')
                    ->getSession()
                    ->wait(1000, "$('.name').children().length > 0");
              }




Thursday, 7 June 12
Steps To Use For Testing JS


       See: http://mink.behat.org for tips on what we can do.




Thursday, 7 June 12
Exercise Three:
                      Hello World On The Web
                           With Javascript



Thursday, 7 June 12
ExerciseThree

                      Extend your solution from the previous exercise.

     Use the supplied jQuery plugin to make your form suggest
        names as the user enters letters into the name field.
                     See hint.php for some clues.




Thursday, 7 June 12
The BDD Workflow
                           1. Open features/hello.feature

           2. Write additional scenarios to test the ‘autocomplete’
                                 functionality

                      3. Run behat features/hello.feature

                 4. Add steps to FeatureContext.php and complete

                      5. Run behat features/hello.feature

Thursday, 7 June 12
The BDD Workflow
                                   6. FAIL

                       7. Write additional functionality

                                   8. PASS




Thursday, 7 June 12
Dynamic Fixture Building: Phabric



                      Shameless self promotion. I Built it.
Thursday, 7 June 12
So Far...




Thursday, 7 June 12
Options For Loading Data


           SQL Fixtures                   Behat’s Fixture
                                             Loading
                      Steps With SQL in                     Phabric

Thursday, 7 June 12
I Don’t like Fixture Files.




Thursday, 7 June 12
Behat’s Fixture Building Tool
    http://propel.posterous.com/propel2-meets-behat-for-the-win




Thursday, 7 June 12
Phabric




Thursday, 7 June 12
Phabric Features
                      Represent Table Data In A Gherkin Table Node


       Scenario: Basic Data Insert
       Given The following conference exists
           | name        | description                       | cdate               |
           | Symfony Day | Anual Symfony conference in Paris | 2011-10-21 09:00:00 |
           | Zend Con    | Zend Conference in San Fran       | 2011-10-17 09:00:00 |
       When I am on "/index.php"
       And I wait for 10 seconds
       Then I should see "Zend Con" in the ".conf" element




Thursday, 7 June 12
Phabric Features
               Map Business Friendly Names To Column Headers


    Scenario: Change Column Names
    Given The following conference exists
        | Conf Name   | Conf Description                  | Conf Date           |
        | Symfony Day | Annual Symfony conference in Paris| 2011-10-21 09:00:00 |
        | Zend Con    | Zend Conference in San Fran       | 2011-10-17 09:00:00 |
    When I am on "/index.php"
    And I wait for 10 seconds
    Then I should see "Zend Con" in the ".conf" element




Thursday, 7 June 12
Phabric Features
                      Default Values Allow You To Omit Columns


     Scenario: Use a default value - use default value for conference description.
     Given The following conference exists
         | Conf Name   | Conf Date         |
         | Symfony Day | 21/10/2011 09:00 |
         | Zend Con    | 17/10/2011 09:00 |
     When I am on "/index.php"
     And I wait for 10 seconds
     Then I should see "Zend Con" in the ".conf" element




Thursday, 7 June 12
Phabric Features
Transformations Allow Data To Be Reformatted Before Insert
                or Update to the Database.

         Scenario: Change Column Data - Reformat date
         Given The following conference exists
             | Conf Name   | Conf Description                  | Conf Date        |
             | Symfony Day | Anual Symfony conference in Paris | 21/10/2011 09:00 |
             | Zend Con    | Zend Conference in San Fran       | 17/10/2011 09:00 |
         When I am on "/index.php"
         And I wait for 10 seconds
         Then I should see "Zend Con" in the ".conf" element




Thursday, 7 June 12
Phabric Features
                       Relationships Supported

        Powered By Doctrine DBAL - Works On Most Popular
                            Databases

    Interfaces Provided To Integrate Your Own Data Providers

                          Easy Configuration

      State is set up in the test - clear visibility of what is being
                                 tested

Thursday, 7 June 12
Phabric Demo




Thursday, 7 June 12
A side note: Hooks




Thursday, 7 June 12
Exercise Four: Play With Phabric




Thursday, 7 June 12
Exercise Four

       Use the supplied example to populate the web page with
                        this mornings tutorials.




Thursday, 7 June 12
Common Contexts




Thursday, 7 June 12
What: Out the box solutions to common problems.
           Where: https://github.com/Behat/CommonContexts




Thursday, 7 June 12
My Favourite & Example


                      WebApi Context - Used to test web services.




Thursday, 7 June 12
Using A Common Context
                          Ensure the common contexts are installed.
               /**
                 * Feature context.
                 */
               class FeatureContext extends MinkContext
               {
                    public function __construct($kernel)
                    {
                        $this->useContext('symfony_extra',
                            new BehatCommonContextsSymfonyMailerContext($kernel)
                        );

                           parent::__construct($kernel);
                      }
               }




                                                Source: https://github.com/Behat/CommonContexts

Thursday, 7 June 12
Exercise Five
                      Use the new WebApi steps to spec a simple API.

          Use the provided files to create a ‘fake’ that satisfies the
                                scenarios.

                       See the misc folder for a WebApi cheat sheet.




Thursday, 7 June 12
Case Study: Behat At Skybet




Thursday, 7 June 12
Sky Bet

              Skybet.com - A large sports betting site in the UK

                      Technology: PHP, MySQL, nodejs

                           Testing: PHPUnit, Behat




Thursday, 7 June 12
Problems

                      1) Definition of Done

                           2) Regression

                      3) Testing The Full Stack




Thursday, 7 June 12
Solution


                 Build a workflow that lets people work together,
                  helps fight regression and provides visibility of
                            progress to the business.




                                   Behat
Thursday, 7 June 12
The Players: Business Analyst




Thursday, 7 June 12
The Players:The Tester




Thursday, 7 June 12
Ninja,
                           Cat Like,
                      Good Looking,
                        Charismatic,
                      Hard Working,
                             Modest
                         Developers.
Thursday, 7 June 12
Solution

    Business Analysts take business requirements write stories.

                             Testers ‘translate’ into Gherkin.

                      Developers write steps and build the feature.




Thursday, 7 June 12
Solution
 A story is ‘done’ when the Behat tests pass and a final check
                    by the BA is complete.

                Tests are run on every commit to master branch.

      Behat tests test the full stack - provide confidence ‘all the
                      moving parts are working’.




Thursday, 7 June 12
Tips From The Trenches


                      Make sure you have your testing mix correct.




Thursday, 7 June 12
Thursday, 7 June 12
Trouble :(




Thursday, 7 June 12
Tips From The Trenches


                      Keep you Gherkin dialect lean and mean.
                      Make someone in charge of the Gherkin.




Thursday, 7 June 12
Tips From The Trenches


       Consider writing abstractions over the provided Behat /
         Mink Steps to make your feature files less brittle.




Thursday, 7 June 12
Time Left / Take Home Exercise




Thursday, 7 June 12
Point Behat At Your Own Website
       And Write Some Scenarios.
                       1) cd /home/tuser/tutorial/06-takehome

                      2) Alter behat.yml to point at your live site

                         3) Write scenarios that test your site




Thursday, 7 June 12
TLDR - Behat Is Super Cool. Go
             Forth And Use It.

                      Questions?


Thursday, 7 June 12
Thanks :-)
              Please Rate My Tutorial: https://joind.in/6218

              Websites & Sources

              http://behat.org
              http://mink.behat.org
              http://dannorth.net/whats-in-a-story/
              http://github.com/benwaine/BehatTutorial
              http://ben-waine.co.uk/blog


Thursday, 7 June 12

Weitere ähnliche Inhalte

Ähnlich wie Behat dpc12

Intro to PHP Testing
Intro to PHP TestingIntro to PHP Testing
Intro to PHP TestingRan Mizrahi
 
Jordan Hubbard Talk @ LISA
Jordan Hubbard Talk @ LISAJordan Hubbard Talk @ LISA
Jordan Hubbard Talk @ LISAguest4c923d
 
A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemLeonard Axelsson
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBYnon Perek
 
Graduating to Jenkins CI for Ruby(-on-Rails) Teams
Graduating to Jenkins CI for Ruby(-on-Rails) TeamsGraduating to Jenkins CI for Ruby(-on-Rails) Teams
Graduating to Jenkins CI for Ruby(-on-Rails) TeamsDaniel Doubrovkine
 
Scaling Puppet Usage to a Global Organization
Scaling Puppet Usage to a Global OrganizationScaling Puppet Usage to a Global Organization
Scaling Puppet Usage to a Global OrganizationPuppet
 
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
 
Pundit
PunditPundit
PunditNet7
 
Puppet at GitHub / ChatOps
Puppet at GitHub / ChatOpsPuppet at GitHub / ChatOps
Puppet at GitHub / ChatOpsPuppet
 
Frozen Rails Slides
Frozen Rails SlidesFrozen Rails Slides
Frozen Rails Slidescarllerche
 
Introduction to Express and Grunt
Introduction to Express and GruntIntroduction to Express and Grunt
Introduction to Express and GruntPeter deHaan
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Tino Isnich
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for RubyHiroshi SHIBATA
 
OSDC 2011 | Advanced Puppet Topics by Ken Barber
OSDC 2011 | Advanced Puppet Topics by Ken BarberOSDC 2011 | Advanced Puppet Topics by Ken Barber
OSDC 2011 | Advanced Puppet Topics by Ken BarberNETWAYS
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywoodehuard
 
Custom Android Code Templates
Custom Android Code TemplatesCustom Android Code Templates
Custom Android Code Templatesmurphonic
 
V mware
V mwareV mware
V mwaredvmug1
 
Puppet Primer, Robbie Jerrom, Solution Architect VMware
Puppet Primer, Robbie Jerrom, Solution Architect VMwarePuppet Primer, Robbie Jerrom, Solution Architect VMware
Puppet Primer, Robbie Jerrom, Solution Architect VMwaresubtitle
 

Ähnlich wie Behat dpc12 (20)

Intro to PHP Testing
Intro to PHP TestingIntro to PHP Testing
Intro to PHP Testing
 
Jordan Hubbard Talk @ LISA
Jordan Hubbard Talk @ LISAJordan Hubbard Talk @ LISA
Jordan Hubbard Talk @ LISA
 
A Tour Through the Groovy Ecosystem
A Tour Through the Groovy EcosystemA Tour Through the Groovy Ecosystem
A Tour Through the Groovy Ecosystem
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Graduating to Jenkins CI for Ruby(-on-Rails) Teams
Graduating to Jenkins CI for Ruby(-on-Rails) TeamsGraduating to Jenkins CI for Ruby(-on-Rails) Teams
Graduating to Jenkins CI for Ruby(-on-Rails) Teams
 
File handaling
File handalingFile handaling
File handaling
 
Scaling Puppet Usage to a Global Organization
Scaling Puppet Usage to a Global OrganizationScaling Puppet Usage to a Global Organization
Scaling Puppet Usage to a Global Organization
 
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
 
Pundit
PunditPundit
Pundit
 
Puppet at GitHub / ChatOps
Puppet at GitHub / ChatOpsPuppet at GitHub / ChatOps
Puppet at GitHub / ChatOps
 
Frozen Rails Slides
Frozen Rails SlidesFrozen Rails Slides
Frozen Rails Slides
 
Introduction to Express and Grunt
Introduction to Express and GruntIntroduction to Express and Grunt
Introduction to Express and Grunt
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for Ruby
 
OSDC 2011 | Advanced Puppet Topics by Ken Barber
OSDC 2011 | Advanced Puppet Topics by Ken BarberOSDC 2011 | Advanced Puppet Topics by Ken Barber
OSDC 2011 | Advanced Puppet Topics by Ken Barber
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywood
 
Custom Android Code Templates
Custom Android Code TemplatesCustom Android Code Templates
Custom Android Code Templates
 
V mware
V mwareV mware
V mware
 
Puppet Primer, Robbie Jerrom, Solution Architect VMware
Puppet Primer, Robbie Jerrom, Solution Architect VMwarePuppet Primer, Robbie Jerrom, Solution Architect VMware
Puppet Primer, Robbie Jerrom, Solution Architect VMware
 

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
 
Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)benwaine
 
Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)benwaine
 
Say no to var_dump
Say no to var_dumpSay no to var_dump
Say no to var_dumpbenwaine
 

Mehr von benwaine (10)

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
 
Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)Acceptance & Integration Testing With Behat (PBC11)
Acceptance & Integration Testing With Behat (PBC11)
 
Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)Acceptance & Integration Testing With Behat (PHPNw2011)
Acceptance & Integration Testing With Behat (PHPNw2011)
 
Say no to var_dump
Say no to var_dumpSay no to var_dump
Say no to var_dump
 

Kürzlich hochgeladen

UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceMartin Humpolec
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.francesco barbera
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataCloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataSafe Software
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 

Kürzlich hochgeladen (20)

UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your Salesforce
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataCloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 

Behat dpc12

  • 1. ACCEPTANCE & INTEGRATION TESTING WITH BEHAT DPC 2012 - Ben Waine - @bwaine https://joind.in/6218 Thursday, 7 June 12
  • 2. The Environment Oracle Open Box Ubuntu 12.12 Behat + Examples Installed 1. Get Open Box and the VHD from the provided USB stick. 2. Install Open Box 3. Load the VHD Thursday, 7 June 12
  • 4. BEN WAINE • Freelance Software Engineer •Worked with Behat at Sky and IPC •DPC was the second conference I ever attended in 2009. Glad to be back! •Twitter: @bwaine Thursday, 7 June 12
  • 5. Todays Roadmap 1. Introduction to BDD and Behat 2. How to Write Behat Tests 3. Mink - UI Testing With Behat 4. Mink - Javascript Testing 5. Phabric - Fixture Building 6. Behat - Common Contexts 7. Case Study - Behat In The Wild 8. Tips From The Trenches 9. Questions Thursday, 7 June 12
  • 6. Todays Roadmap 1. Introduction to BDD and Behat 2. How to Write Behat Tests 3. Mink - UI Testing With Behat 4. Mink - Javascript Testing 5. Phabric - Fixture Building 6. Behat - Common Contexts 7. Case Study - Behat In The Wild 8. Tips From The Trenches 9. Questions Thursday, 7 June 12
  • 10. Dan North - Whats In A Story? http://dannorth.net/whats-in-a-story/ Thursday, 7 June 12
  • 11. Dan North’s Recipe For A Story Title (one line describing the story) Narrative: As a [role] I want [feature] So that [benefit] Acceptance Criteria: (presented as Scenarios) Scenario 1: Title Given [context] And [some more context]... When [event] Then [outcome] And [another outcome]... Thursday, 7 June 12
  • 12. Behat ‘A open source behaviour driven development [testing] framework’ ‘Inspired by Ruby’s Cucumber project’ Thursday, 7 June 12
  • 13. Behat - What Can We Do With It? Test Anything! Web Applications Shell Scripts Your developers relationship Web Services PHP Scripts skills Thursday, 7 June 12
  • 14. Where Does Behat Sit In The BDD Ecosystem? PHPSpec - Class Level BDD Behat - Service / UI Level Testing Thursday, 7 June 12
  • 15. BDD == TDD?? http://dannorth.net/2012/05/31/bdd-is-like-tdd-if/ Thursday, 7 June 12
  • 16. Behat - Installation So Easy I’m Not Even Covering It. Composer Pear Phar Github Thursday, 7 June 12
  • 17. My Friend Shashi - http://lestbddphp.wordpress.com/2012/05/07/enjoy- minkextension-for-behat/ Great article on setting up Behat 2.4 (latest version) Thursday, 7 June 12
  • 18. Testing Unix’s famous ‘ls’ command An Example From behat.org 1. In the VM open Sublime Text 2 2. cd /home/tuser/tutorial/01-LinuxCommands Thursday, 7 June 12
  • 19. Testing Unix’s famous ‘ls’ command What does a behat test consist of? 1. Run: bin/behat features/ls.feature 2. Open features/ls.feature 3. Open features/bootstrap/FeatureContext.php Thursday, 7 June 12
  • 21. Testing Unix’s famous ‘ls’ command features/ls.feature Feature: ls In order to see the directory structure As a UNIX user I need to be able to list the current directory's contents Scenario: List 2 files in a directory Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """ Source: http://docs.behat.org/quick_intro.html Thursday, 7 June 12
  • 22. Dan North’s Recipe For A Story Title (one line describing the story) Narrative: As a [role] I want [feature] So that [benefit] Acceptance Criteria: (presented as Scenarios) Scenario 1: Title Given [context] And [some more context]... When [event] Then [outcome] And [another outcome]... Thursday, 7 June 12
  • 23. Steps - Plain Old PHP Thursday, 7 June 12
  • 24. features/bootstrap/FeatureContext.php <?php use BehatBehatContextBehatContext, BehatBehatExceptionPendingException; use BehatGherkinNodePyStringNode, BehatGherkinNodeTableNode; class FeatureContext extends BehatContext { private $output; /** @Given /^I am in a directory "([^"]*)"$/ */ public function iAmInADirectory($dir) { if (!file_exists($dir)) { mkdir($dir); } chdir($dir); } Source: http://docs.behat.org/quick_intro.html 1/2 Thursday, 7 June 12
  • 25. features/bootstrap/FeatureContext.php /** @Given /^I have a file named "([^"]*)"$/ */ public function iHaveAFileNamed($file) { touch($file); } /** @When /^I run "([^"]*)"$/ */ public function iRun($command) { exec($command, $output); $this->output = trim(implode("n", $output)); } /** @Then /^I should get:$/ */ public function iShouldGet(PyStringNode $string) { if ((string) $string !== $this->output) { throw new Exception( "Actual output is:n" . $this->output ); } } 2/2 Thursday, 7 June 12
  • 26. Testing Unix’s famous ‘ls’ command What does a behat test consist of? Feature Files & Feature Contexts Which contain: Features / Stories and Steps Thursday, 7 June 12
  • 28. Exercise One: Hello World Thursday, 7 June 12
  • 29. Exercise One Write a php script which takes the users name as it’s only argument. When executed it should write ‘Hello’ to the screen. eg. Hello Ben If no name is given then it should output ‘Hello Stranger’ Thursday, 7 June 12
  • 30. The BDD approach - write scenarios that define behaviour first. Thursday, 7 June 12
  • 31. Setting Up A Project 1. cd /home/tuser/tutorial/02-HelloScript 2. run bin/behat --init Thursday, 7 June 12
  • 32. Behat Killer Feature - Write A Step Get The Regex For Free! Thursday, 7 June 12
  • 33. The BDD Workflow 1. Create features/hello.feature 2. Write a scenario to test the ‘hello’ script 3. Run bin/behat features/hello.feature 4. Copy the steps into features/bootstrap/ FeatureContext.php Thursday, 7 June 12
  • 34. Clues 1. The Command is in another directory. Change to that directory in the given step? 2. When is an event or action 3. Then tests the event Thursday, 7 June 12
  • 35. The BDD Workflow 1. Create features/hello.feature 2. Write a scenario to test the ‘hello’ script 3. Run bin/behat features/hello.feature 4. Copy the steps into features/bootstrap/ FeatureContext.php Thursday, 7 June 12
  • 36. The BDD Workflow 5. Complete the methods in the FeatureContext.php file. 6. Run bin/behat features/hello.feature 7. FAIL 8. Write the Hello Script. 9. PASS Thursday, 7 June 12
  • 37. Dan North Revisited: Making a Good Story The title should describe an activity The narrative should include a role, a feature and a benefit The scenario title should say what’s different The scenario should be described in terms of Givens, Events and Outcomes The givens should define all of, and no more than, the required context The event should describe the feature The story should be small enough to fit in an iteration Thursday, 7 June 12
  • 39. UI Testing With Behat & Mink Thursday, 7 June 12
  • 41. Mink Goutte Web Driver Zombie Js Selenium Sahi Thursday, 7 June 12
  • 42. Mink - A UI Testing Tool Abstraction Headless Browser (Goutte) Makes HTTP calls and inspect the output Fast and lightweight Can’t test Javascipt / AJAX Browser Controller (Sahi / Selenium / WebDriver) Control a real browser Simulates user interaction with a web site Can test javascript / AJAX Slower than headless browser Thursday, 7 June 12
  • 43. Included With Mink A new context class to use Bundled steps to test UI elements with. Eg: Given I am on "/wiki/Main_Page" When I fill in "search" with "Behavior Driven Development" And I press "searchButton" Then I should see "agile software development" Source: http://behat.org/cookbook/behat_and_mink.html Thursday, 7 June 12
  • 44. Using MinkContext If you have custom steps or an existing FeatureContext <?php class FeatureContext extends BehatContext { public function __construct(array $parameters) { $this->useContext( 'mink', new BehatMinkExtensionContextMinkContext ); } } Thursday, 7 June 12
  • 45. Exercise Two: Hello World On The Web Thursday, 7 June 12
  • 46. Exercise Two Write a simple web page with a form. The form should have a single field ‘name’. When typing in a name and pressing submit, the page should reload and print the message ‘Hello _name_’ eg. Hello Ben On the page with the greeting a link with the text ‘again’ should take you back to the original form page. Thursday, 7 June 12
  • 47. Setting Up A Project 1. cd /home/tuser/tutorial/03-HelloPage 2. run bin/behat --init 3. Web page goes in the ‘public’ directory 4. Add behat.yml to 03-HelloPage See example misc/behat.yml Thursday, 7 June 12
  • 48. Using MinkContext If you have custom steps or an existing FeatureContext <?php class FeatureContext extends BehatContext { public function __construct(array $parameters) { $this->useContext( 'mink', new BehatMinkExtensionContextMinkContext ); } } Thursday, 7 June 12
  • 49. Using MinkContext New in 2.4 - If Mink extension is installed and you have no custom steps. It’s automatic! Great for testers. Thursday, 7 June 12
  • 50. The BDD Workflow 1. Create features/hello.feature 2. Write a scenario to test the ‘hello’ page Use bundled Mink Steps 3. Use MinkContext 4. Run bin/behat features/hello.feature Wow no new steps required! Thursday, 7 June 12
  • 51. The BDD Workflow 5. FAIL 6. Write web page 7. PASS Thursday, 7 June 12
  • 52. Debugging Steps Then /^print last response$/ Then /^show last response$/ ‘And I Wait’ - implement yourself with fgets Lets try this on the test we have just written. Thursday, 7 June 12
  • 54. Tagging Tests For Javascript Testing Use tags to tell Mink to use a full browser rather than Goutte. @javascript Scenario: As an attendee I should be able to tag scenarios after reading this Given I am testing javascript When I read this slide Then I'll tag scenarios with @javascript LIKE A BOSS Thursday, 7 June 12
  • 55. Steps To Use For Testing JS Custom steps which manipulate the mink session. /** * @Then /^I wait for the suggestion box to appear$/ */ public function iWaitForTheSuggestionBoxToAppear() { $this->getSubcontext('mink') ->getSession() ->wait(1000, "$('.name').children().length > 0"); } Thursday, 7 June 12
  • 56. Steps To Use For Testing JS See: http://mink.behat.org for tips on what we can do. Thursday, 7 June 12
  • 57. Exercise Three: Hello World On The Web With Javascript Thursday, 7 June 12
  • 58. ExerciseThree Extend your solution from the previous exercise. Use the supplied jQuery plugin to make your form suggest names as the user enters letters into the name field. See hint.php for some clues. Thursday, 7 June 12
  • 59. The BDD Workflow 1. Open features/hello.feature 2. Write additional scenarios to test the ‘autocomplete’ functionality 3. Run behat features/hello.feature 4. Add steps to FeatureContext.php and complete 5. Run behat features/hello.feature Thursday, 7 June 12
  • 60. The BDD Workflow 6. FAIL 7. Write additional functionality 8. PASS Thursday, 7 June 12
  • 61. Dynamic Fixture Building: Phabric Shameless self promotion. I Built it. Thursday, 7 June 12
  • 63. Options For Loading Data SQL Fixtures Behat’s Fixture Loading Steps With SQL in Phabric Thursday, 7 June 12
  • 64. I Don’t like Fixture Files. Thursday, 7 June 12
  • 65. Behat’s Fixture Building Tool http://propel.posterous.com/propel2-meets-behat-for-the-win Thursday, 7 June 12
  • 67. Phabric Features Represent Table Data In A Gherkin Table Node Scenario: Basic Data Insert Given The following conference exists | name | description | cdate | | Symfony Day | Anual Symfony conference in Paris | 2011-10-21 09:00:00 | | Zend Con | Zend Conference in San Fran | 2011-10-17 09:00:00 | When I am on "/index.php" And I wait for 10 seconds Then I should see "Zend Con" in the ".conf" element Thursday, 7 June 12
  • 68. Phabric Features Map Business Friendly Names To Column Headers Scenario: Change Column Names Given The following conference exists | Conf Name | Conf Description | Conf Date | | Symfony Day | Annual Symfony conference in Paris| 2011-10-21 09:00:00 | | Zend Con | Zend Conference in San Fran | 2011-10-17 09:00:00 | When I am on "/index.php" And I wait for 10 seconds Then I should see "Zend Con" in the ".conf" element Thursday, 7 June 12
  • 69. Phabric Features Default Values Allow You To Omit Columns Scenario: Use a default value - use default value for conference description. Given The following conference exists | Conf Name | Conf Date | | Symfony Day | 21/10/2011 09:00 | | Zend Con | 17/10/2011 09:00 | When I am on "/index.php" And I wait for 10 seconds Then I should see "Zend Con" in the ".conf" element Thursday, 7 June 12
  • 70. Phabric Features Transformations Allow Data To Be Reformatted Before Insert or Update to the Database. Scenario: Change Column Data - Reformat date Given The following conference exists | Conf Name | Conf Description | Conf Date | | Symfony Day | Anual Symfony conference in Paris | 21/10/2011 09:00 | | Zend Con | Zend Conference in San Fran | 17/10/2011 09:00 | When I am on "/index.php" And I wait for 10 seconds Then I should see "Zend Con" in the ".conf" element Thursday, 7 June 12
  • 71. Phabric Features Relationships Supported Powered By Doctrine DBAL - Works On Most Popular Databases Interfaces Provided To Integrate Your Own Data Providers Easy Configuration State is set up in the test - clear visibility of what is being tested Thursday, 7 June 12
  • 73. A side note: Hooks Thursday, 7 June 12
  • 74. Exercise Four: Play With Phabric Thursday, 7 June 12
  • 75. Exercise Four Use the supplied example to populate the web page with this mornings tutorials. Thursday, 7 June 12
  • 77. What: Out the box solutions to common problems. Where: https://github.com/Behat/CommonContexts Thursday, 7 June 12
  • 78. My Favourite & Example WebApi Context - Used to test web services. Thursday, 7 June 12
  • 79. Using A Common Context Ensure the common contexts are installed. /** * Feature context. */ class FeatureContext extends MinkContext { public function __construct($kernel) { $this->useContext('symfony_extra', new BehatCommonContextsSymfonyMailerContext($kernel) ); parent::__construct($kernel); } } Source: https://github.com/Behat/CommonContexts Thursday, 7 June 12
  • 80. Exercise Five Use the new WebApi steps to spec a simple API. Use the provided files to create a ‘fake’ that satisfies the scenarios. See the misc folder for a WebApi cheat sheet. Thursday, 7 June 12
  • 81. Case Study: Behat At Skybet Thursday, 7 June 12
  • 82. Sky Bet Skybet.com - A large sports betting site in the UK Technology: PHP, MySQL, nodejs Testing: PHPUnit, Behat Thursday, 7 June 12
  • 83. Problems 1) Definition of Done 2) Regression 3) Testing The Full Stack Thursday, 7 June 12
  • 84. Solution Build a workflow that lets people work together, helps fight regression and provides visibility of progress to the business. Behat Thursday, 7 June 12
  • 85. The Players: Business Analyst Thursday, 7 June 12
  • 87. Ninja, Cat Like, Good Looking, Charismatic, Hard Working, Modest Developers. Thursday, 7 June 12
  • 88. Solution Business Analysts take business requirements write stories. Testers ‘translate’ into Gherkin. Developers write steps and build the feature. Thursday, 7 June 12
  • 89. Solution A story is ‘done’ when the Behat tests pass and a final check by the BA is complete. Tests are run on every commit to master branch. Behat tests test the full stack - provide confidence ‘all the moving parts are working’. Thursday, 7 June 12
  • 90. Tips From The Trenches Make sure you have your testing mix correct. Thursday, 7 June 12
  • 93. Tips From The Trenches Keep you Gherkin dialect lean and mean. Make someone in charge of the Gherkin. Thursday, 7 June 12
  • 94. Tips From The Trenches Consider writing abstractions over the provided Behat / Mink Steps to make your feature files less brittle. Thursday, 7 June 12
  • 95. Time Left / Take Home Exercise Thursday, 7 June 12
  • 96. Point Behat At Your Own Website And Write Some Scenarios. 1) cd /home/tuser/tutorial/06-takehome 2) Alter behat.yml to point at your live site 3) Write scenarios that test your site Thursday, 7 June 12
  • 97. TLDR - Behat Is Super Cool. Go Forth And Use It. Questions? Thursday, 7 June 12
  • 98. Thanks :-) Please Rate My Tutorial: https://joind.in/6218 Websites & Sources http://behat.org http://mink.behat.org http://dannorth.net/whats-in-a-story/ http://github.com/benwaine/BehatTutorial http://ben-waine.co.uk/blog Thursday, 7 June 12