SlideShare a Scribd company logo
1 of 57
@marcos_quesada
Who am I?
                    ●   Always hungry of knowledge
                    ●   Symfony 2 lover
                    ●   Rigor path follower... or searcher
                    ●   Google Addict
                    ●   Testing believer
                    ●   Backend Developer at SocialPoint

@marcos_quesada
marcos.quesadas@gmail.com
Index
●   TDD Introduction
●   Mockery
●   BDD Introduction
●   Behat
●   Mink
●   Selenium
Which is the value of testing?
●   TDD & Unit Tests
●   BDD
        –   SpecBDD
        –   StoryBDD
●   Acceptance Tests
●   Integration Tests
Unit Test
●   Driven Development
●   Focus on class Methods
●   Conceptually Isolated test
●   Value?
Basic Unit Test
TDD & Unit Testing
●   Development time increased
        –   25%-15% time when mastering
●   Design and Quality code is dramatically
    increased
●   Code coverage metrics
●   Unit Test !== Integration tests
Unit Testing

●   Class interactions:
        –   Things become tricky
        –   How much isolation we need?
        –   Lot's of Mocks&Stubs... But it is very Useful?
Mocking class behavior
Mockery

●   Alternative to PHPUnit
●   simple&flexible PHP mock object framework
●   Focus on Easy mocking
●   Great API
Basic Mock with Mockery
Mock Example with PHPUnit




Mock Example with Mockery
●Does things that others can not
●   Create Mocks from object instances
●Does things that others can not
●   Great typeHinting definition, from Classes or
    interfaces, even both!!



●   Fluent interface definition
Does things that others can not
●   Define public attributes from Mock Class
        –   $this->container->get('router')
●   Mocking Public Static Methods
●   Ability to Mock Final Class
●   Return different Mock responses as secuence
            $this->get('router')
            $this->get('my.service')
OK! Great... but
●   Unitary Test must be ATRIP:
        –   Repeatable, Isolated, Independent, Automated
●   But It's no easy to write correct Tests
        –   What should I test?
        –   How should I name this test?
        –   Where do I start?
        –   How much to test?
        –   How to understand why a test fail?
How much value has indeed?




            Image taken from Alvaro Videla presentation
So ...
BDD

●   Behavior Driven Development
●   Created by Dan North
●   Migrates test focus to behavior
●   SpecBDD Vs StoryBDD
●   PHPSpec orientation
●How much value has indeed?
●   We have moved our focus from methods to
    class interactions
●   Code becomes:
          –   Better designed
          –   Focused on Behavior
●   But ...
          –   AGNY No extra features are needed
          –   Acceptance feature is not well delimited
●   Testing is great but...
●   Bussines has nothing to do with that
       –   It should ….
●   Classes are for developers
●   What we are missing?
       –   As developers we create funcionallities
       –   How much extra work are we adding to our
            development cycle?
Agile Development Approach
    Histories are created upon Tasks
●   User Stories describe a feature's benefit in
    context
●   Scenarios are executable acceptance criteria
Avoid misunderstandings
Behat
●   Behat is a Bussines expectation framework
●   Created by @everzet
●   Behat is a Cucumber port to PHP
●   What mades that huge difference from
    SpecBDD to StoryBDD ?
       –   Feature definition
       –   Domain Specific Language (Gherkin)
Behat
●   Behat test a feature by executing its scenarios
    steps in a context
●   Is driven by bussines value
●   feature description:
        –   collaboration bettween developers and non-
              techies
●   Clear feature description&piorization gives as a
    result better estimation times
Gherkin
●   Easy to understand
●   Step definitions becomes test code
Basic Feature Description
More Feature Definition
Let's install it
●   Install PHP base
         –   git clone git@github.com:marcosQuesada/Behat-Base.git
         –   curl http://getcomposer.org/installer | php
         –   php composer.phar install
         –   bin/behat --init
●   Or Install Sf2 Base
         –   git clone git@github.com:marcosQuesada/Symfony2-Behat-
                Base.git
         –   behat --init @AcmeDemoBundle
What's behind Behat
How does it work?
●   Behat give us our skeleton needs
●   uses Behat Known Regular Expressions
       –   Regex to grab test values
●   Uses any assertion tool to get response
       –   PHPUnit
       –   PHP Exceptions
API Feature Exercise
●   Example using Behat + Guzzle to test a public API (google maps
    postal code)
●   Get Feature description
         –   git clone git@github.com:marcosQuesada/API-Workshop-Exercise.git
●   Run api-geo Feature
         –   Behat




                  Time to code Step 1!
What we have?
●   Acceptance test pass!
●   Feature context steps are reusable
Context becomes BIG
●   Context segregation
       –   single implementation
●   Behat Contexts Extensions
       –   Behatch contexts
       –   DoctrineDataFixturesExtension
       –   MINK Context
       –   Common Context ...
Working with Subcontexts
●   Adding subcontexts




●   Subcontext bridging
Refactor Your Code
●   You have tested an external api
●   Time to create your own implementation
         –   Use Your previous tests!
●   Run api Feature
         –   Behat




                 Time to code Step 2!
Behat Event System
Behat Event System
Mink Context
●   Web Behavior expectation
●   Support HTML - @javascript
●   Lot's of drivers
        –   Headless Browser
                ●   Goutte
        –   Browser handler
                ●   Selenium
                ●   Sahi
                ●   Symfony 2 webDriver
Install Mink
●   Behat.yml
Mink API
●    $this->visit($url);
●    $this->getSession()->getPage()->getContent()
●    $this->getSession()->getStatusCode()
●    $this->getSession()->reload()
●    $this->getSession()->back()
●    $this->getSession()->forward()evaluate JS expressions
●    $this->getSession()->evaluateScrip("alert('Hello'");
●    wait N milliseconds or till JS expression becomes true
    $this->getSession()->wait(5000,
         "$('.suggest_class').children().lenght > 0"
    );
Check available definitions
●   Exec:
      –   behat –definitions l (behat -dl)
      –   Then /^print last response$/
      –   Then /^show last response$/
Tools to manage the web browser




               Image taken from Jakub Zalas presentation
Tools to work with forms




           Image taken from Jakub Zalas presentation
Tools for queryng the DOM




            Image taken from Jakub Zalas presentation
Tools to examine responses




And even more features ...
                             Image taken from Jakub Zalas presentation
Selectors
●   Behat driver uses Xpath Selectors
        –   $xpath = $handler->selectorToXpath('xpath',
              '//html');
●   CSS Selectors can be translated
        –   echo $cssSelector->translateToXPath('h1 > a');
●   Finder Methods
       $fieldElement = $page->find('named',
          array('field', 'id|name|value|label')
       );
       $elementByCss = $page->find('css', 'h3 > a');
Behat+Mink+Selenium Example
●   Selenium server:
       –   Download from http://seleniumhq.org/download
       –   java -jar selenium-server-standalone-2.15.0.jar
●   Behat.yml
       default:
         context:
            parameters:
                javascript_session: selenium
                base_url: http://en.wikipedia.org/
                browser: firefox
                show_cmd: open %s
Feature Description

Feature: Blog Search
    In order to search blogs
    As a sauce user
    I need see blogs

@javascript
Scenario: Search Behat Blogs
  Given I am on "/wiki/Wikipedia"
  When I fill in "s" with "behat"
  And I press "Search"
  Then I should see "Behat"
Adding Sauce
Adding Sauce
●   Sauce Labs easy integration
       –   Username & API key
●   Create sauce.yml
       default:
         context:
            parameters:
                default_session: selenium
                javascript_session: selenium
                base_url: http://en.wikipedia.org/xxx
                browser: firefox
                selenium:
                   host: ondemand.saucelabs.com
                   port: 80
                   browser: >
                     {
                         "username": "name",
                         "access-key": "APIkey",
                         "browser":    "firefox",
                         "browser-version": "7",
                         "os":      "Windows 2003",
                         "name":      "Testing Selenium with Behat"
                      }
Running on Sauce
●   exec with:
        –   behat -c sauce.yml
●   View result video of this job:
        –   http://snipurl.com/21huj12
●     reports generate in 'report/report.html'
Testing Javascript
●   Not posible on Headless Browser
        –   Goutte
●   Javascript element interaction
        –   Symfony 2 webdriver
        –   Selenium2
Mink Login Feature Exercise
●   Mink + Selenium server
●   Download Selenium Server
         –   http://seleniumhq.org/download/
●   Get Feature description
         –   git clone git@github.com:marcosQuesada/Login-Workshop-Exercise.git
●   Run login Feature




●   Do what you want …. but Pass it again
Conclusion
●   Behat features are meaningful
●   Behat is Driven Development
●   Behat is complementary to TDD and Unit
    testing
●   Best approach to service assurance
●   Let's use it now!
References
●   Mockery:
            https://github.com/padraic/mockery
●   Behat:
            http://behat.org/
●   Mink:
            http://mink.behat.org/
Workshop Links
●   Behat PHP Base
          –   https://github.com/marcosQuesada/Behat-Base.git
●   Symfony 2 Behat Base
          –   https://github.com/marcosQuesada/Symfony2-Behat-Base
●   Workshop Features
          –   https://github.com/marcosQuesada/API-Workshop-Exercise.git
          –   https://github.com/marcosQuesada/Login-Workshop-Exercise
●   Mockery Examples
          –   https://github.com/marcosQuesada/MockerySf2
●   My Exercise Solutions
          –   https://github.com/marcosQuesada/Api-Behat-Testing
          –   https://github.com/marcosQuesada/Behat-Login-Exercise
Thank you!


     Twitter:   @marcos_quesada
     Linkedin: marcosquesada
     marcos.quesadas@gmail.com

More Related Content

What's hot

Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolvedBhagwat Kumar
 
Come and Play! with Java EE 7
Come and Play! with Java EE 7Come and Play! with Java EE 7
Come and Play! with Java EE 7Antonio Goncalves
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
Fullstack End-to-end test automation with Node.js, one year later
Fullstack End-to-end test automation with Node.js, one year laterFullstack End-to-end test automation with Node.js, one year later
Fullstack End-to-end test automation with Node.js, one year laterMek Srunyu Stittri
 
Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014Chen-en Lu
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overviewjeresig
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideMek Srunyu Stittri
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEBGR8Conf
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSShekhar Gulati
 
Ten Minutes To Tellurium
Ten Minutes To TelluriumTen Minutes To Tellurium
Ten Minutes To TelluriumJohn.Jian.Fang
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Jeado Ko
 
Acceptance Test-driven Development with Cucumber-jvm
Acceptance Test-driven Development with Cucumber-jvmAcceptance Test-driven Development with Cucumber-jvm
Acceptance Test-driven Development with Cucumber-jvmChristopher Bartling
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpdayStephan Hochdörfer
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXAngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXJWORKS powered by Ordina
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript TestingScott Becker
 
The Gist of React Native
The Gist of React NativeThe Gist of React Native
The Gist of React NativeDarren Cruse
 

What's hot (20)

Geb with spock
Geb with spockGeb with spock
Geb with spock
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
Come and Play! with Java EE 7
Come and Play! with Java EE 7Come and Play! with Java EE 7
Come and Play! with Java EE 7
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
Fullstack End-to-end test automation with Node.js, one year later
Fullstack End-to-end test automation with Node.js, one year laterFullstack End-to-end test automation with Node.js, one year later
Fullstack End-to-end test automation with Node.js, one year later
 
Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEB
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
 
Ten Minutes To Tellurium
Ten Minutes To TelluriumTen Minutes To Tellurium
Ten Minutes To Tellurium
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
 
Acceptance Test-driven Development with Cucumber-jvm
Acceptance Test-driven Development with Cucumber-jvmAcceptance Test-driven Development with Cucumber-jvm
Acceptance Test-driven Development with Cucumber-jvm
 
Nicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JSNicolas Embleton, Advanced Angular JS
Nicolas Embleton, Advanced Angular JS
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpday
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXAngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UX
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
 
The Gist of React Native
The Gist of React NativeThe Gist of React Native
The Gist of React Native
 
Night Watch with QA
Night Watch with QANight Watch with QA
Night Watch with QA
 

Similar to Behat Workshop at WeLovePHP

Testing with Codeception
Testing with CodeceptionTesting with Codeception
Testing with CodeceptionJeremy Coates
 
Behat internals for advanced usage. Symfony Camp 2016
Behat internals for advanced usage. Symfony Camp 2016Behat internals for advanced usage. Symfony Camp 2016
Behat internals for advanced usage. Symfony Camp 2016Sergey Polischook
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - Ortus Solutions, Corp
 
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Michael Lihs
 
Hanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcHanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcdenemedeniz
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplateStanislav Petrov
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by ExampleNalin Goonawardana
 
Behave manners for ui testing pycon2019
Behave manners for ui testing pycon2019Behave manners for ui testing pycon2019
Behave manners for ui testing pycon2019Panos Christeas
 
Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsArtur Babyuk
 
Monitoring your VM's at Scale
Monitoring your VM's at ScaleMonitoring your VM's at Scale
Monitoring your VM's at ScaleKris Buytaert
 
Useful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvmUseful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvmAnton Shapin
 
Integration Testing with Behat drupal
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupalOscar Merida
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkSusannSgorzaly
 
Gatling Performance Workshop
Gatling Performance WorkshopGatling Performance Workshop
Gatling Performance WorkshopSai Krishna
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in YiiIlPeach
 
Moodle Development Best Pracitces
Moodle Development Best PracitcesMoodle Development Best Pracitces
Moodle Development Best PracitcesJustin Filip
 
Continuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applicationsContinuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applicationsEvgeniy Kuzmin
 
Towards Continuous Deployment with Django
Towards Continuous Deployment with DjangoTowards Continuous Deployment with Django
Towards Continuous Deployment with DjangoRoger Barnes
 
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...Evgeniy Kuzmin
 

Similar to Behat Workshop at WeLovePHP (20)

Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 
Testing with Codeception
Testing with CodeceptionTesting with Codeception
Testing with Codeception
 
Behat internals for advanced usage. Symfony Camp 2016
Behat internals for advanced usage. Symfony Camp 2016Behat internals for advanced usage. Symfony Camp 2016
Behat internals for advanced usage. Symfony Camp 2016
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
 
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
 
Hanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcHanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvc
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
 
Behave manners for ui testing pycon2019
Behave manners for ui testing pycon2019Behave manners for ui testing pycon2019
Behave manners for ui testing pycon2019
 
Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP Basics
 
Monitoring your VM's at Scale
Monitoring your VM's at ScaleMonitoring your VM's at Scale
Monitoring your VM's at Scale
 
Useful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvmUseful practices of creation automatic tests by using cucumber jvm
Useful practices of creation automatic tests by using cucumber jvm
 
Integration Testing with Behat drupal
Integration Testing with Behat drupalIntegration Testing with Behat drupal
Integration Testing with Behat drupal
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP framework
 
Gatling Performance Workshop
Gatling Performance WorkshopGatling Performance Workshop
Gatling Performance Workshop
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in Yii
 
Moodle Development Best Pracitces
Moodle Development Best PracitcesMoodle Development Best Pracitces
Moodle Development Best Pracitces
 
Continuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applicationsContinuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applications
 
Towards Continuous Deployment with Django
Towards Continuous Deployment with DjangoTowards Continuous Deployment with Django
Towards Continuous Deployment with Django
 
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
 

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
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
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.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
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

Behat Workshop at WeLovePHP

  • 2. Who am I? ● Always hungry of knowledge ● Symfony 2 lover ● Rigor path follower... or searcher ● Google Addict ● Testing believer ● Backend Developer at SocialPoint @marcos_quesada marcos.quesadas@gmail.com
  • 3. Index ● TDD Introduction ● Mockery ● BDD Introduction ● Behat ● Mink ● Selenium
  • 4. Which is the value of testing? ● TDD & Unit Tests ● BDD – SpecBDD – StoryBDD ● Acceptance Tests ● Integration Tests
  • 5. Unit Test ● Driven Development ● Focus on class Methods ● Conceptually Isolated test ● Value?
  • 7. TDD & Unit Testing ● Development time increased – 25%-15% time when mastering ● Design and Quality code is dramatically increased ● Code coverage metrics ● Unit Test !== Integration tests
  • 8. Unit Testing ● Class interactions: – Things become tricky – How much isolation we need? – Lot's of Mocks&Stubs... But it is very Useful?
  • 10. Mockery ● Alternative to PHPUnit ● simple&flexible PHP mock object framework ● Focus on Easy mocking ● Great API
  • 11. Basic Mock with Mockery Mock Example with PHPUnit Mock Example with Mockery
  • 12. ●Does things that others can not ● Create Mocks from object instances
  • 13. ●Does things that others can not ● Great typeHinting definition, from Classes or interfaces, even both!! ● Fluent interface definition
  • 14. Does things that others can not ● Define public attributes from Mock Class – $this->container->get('router') ● Mocking Public Static Methods ● Ability to Mock Final Class ● Return different Mock responses as secuence $this->get('router') $this->get('my.service')
  • 15. OK! Great... but ● Unitary Test must be ATRIP: – Repeatable, Isolated, Independent, Automated ● But It's no easy to write correct Tests – What should I test? – How should I name this test? – Where do I start? – How much to test? – How to understand why a test fail?
  • 16. How much value has indeed? Image taken from Alvaro Videla presentation
  • 18. BDD ● Behavior Driven Development ● Created by Dan North ● Migrates test focus to behavior ● SpecBDD Vs StoryBDD ● PHPSpec orientation
  • 19. ●How much value has indeed? ● We have moved our focus from methods to class interactions ● Code becomes: – Better designed – Focused on Behavior ● But ... – AGNY No extra features are needed – Acceptance feature is not well delimited
  • 20. Testing is great but... ● Bussines has nothing to do with that – It should …. ● Classes are for developers ● What we are missing? – As developers we create funcionallities – How much extra work are we adding to our development cycle?
  • 21. Agile Development Approach Histories are created upon Tasks ● User Stories describe a feature's benefit in context ● Scenarios are executable acceptance criteria
  • 23. Behat ● Behat is a Bussines expectation framework ● Created by @everzet ● Behat is a Cucumber port to PHP ● What mades that huge difference from SpecBDD to StoryBDD ? – Feature definition – Domain Specific Language (Gherkin)
  • 24. Behat ● Behat test a feature by executing its scenarios steps in a context ● Is driven by bussines value ● feature description: – collaboration bettween developers and non- techies ● Clear feature description&piorization gives as a result better estimation times
  • 25. Gherkin ● Easy to understand ● Step definitions becomes test code
  • 28. Let's install it ● Install PHP base – git clone git@github.com:marcosQuesada/Behat-Base.git – curl http://getcomposer.org/installer | php – php composer.phar install – bin/behat --init ● Or Install Sf2 Base – git clone git@github.com:marcosQuesada/Symfony2-Behat- Base.git – behat --init @AcmeDemoBundle
  • 30. How does it work? ● Behat give us our skeleton needs ● uses Behat Known Regular Expressions – Regex to grab test values ● Uses any assertion tool to get response – PHPUnit – PHP Exceptions
  • 31. API Feature Exercise ● Example using Behat + Guzzle to test a public API (google maps postal code) ● Get Feature description – git clone git@github.com:marcosQuesada/API-Workshop-Exercise.git ● Run api-geo Feature – Behat Time to code Step 1!
  • 32. What we have? ● Acceptance test pass! ● Feature context steps are reusable
  • 33. Context becomes BIG ● Context segregation – single implementation ● Behat Contexts Extensions – Behatch contexts – DoctrineDataFixturesExtension – MINK Context – Common Context ...
  • 34. Working with Subcontexts ● Adding subcontexts ● Subcontext bridging
  • 35. Refactor Your Code ● You have tested an external api ● Time to create your own implementation – Use Your previous tests! ● Run api Feature – Behat Time to code Step 2!
  • 38. Mink Context ● Web Behavior expectation ● Support HTML - @javascript ● Lot's of drivers – Headless Browser ● Goutte – Browser handler ● Selenium ● Sahi ● Symfony 2 webDriver
  • 39. Install Mink ● Behat.yml
  • 40. Mink API ● $this->visit($url); ● $this->getSession()->getPage()->getContent() ● $this->getSession()->getStatusCode() ● $this->getSession()->reload() ● $this->getSession()->back() ● $this->getSession()->forward()evaluate JS expressions ● $this->getSession()->evaluateScrip("alert('Hello'"); ● wait N milliseconds or till JS expression becomes true $this->getSession()->wait(5000, "$('.suggest_class').children().lenght > 0" );
  • 41. Check available definitions ● Exec: – behat –definitions l (behat -dl) – Then /^print last response$/ – Then /^show last response$/
  • 42. Tools to manage the web browser Image taken from Jakub Zalas presentation
  • 43. Tools to work with forms Image taken from Jakub Zalas presentation
  • 44. Tools for queryng the DOM Image taken from Jakub Zalas presentation
  • 45. Tools to examine responses And even more features ... Image taken from Jakub Zalas presentation
  • 46. Selectors ● Behat driver uses Xpath Selectors – $xpath = $handler->selectorToXpath('xpath', '//html'); ● CSS Selectors can be translated – echo $cssSelector->translateToXPath('h1 > a'); ● Finder Methods $fieldElement = $page->find('named', array('field', 'id|name|value|label') ); $elementByCss = $page->find('css', 'h3 > a');
  • 47. Behat+Mink+Selenium Example ● Selenium server: – Download from http://seleniumhq.org/download – java -jar selenium-server-standalone-2.15.0.jar ● Behat.yml default: context: parameters: javascript_session: selenium base_url: http://en.wikipedia.org/ browser: firefox show_cmd: open %s
  • 48. Feature Description Feature: Blog Search In order to search blogs As a sauce user I need see blogs @javascript Scenario: Search Behat Blogs Given I am on "/wiki/Wikipedia" When I fill in "s" with "behat" And I press "Search" Then I should see "Behat"
  • 50. Adding Sauce ● Sauce Labs easy integration – Username & API key ● Create sauce.yml default: context: parameters: default_session: selenium javascript_session: selenium base_url: http://en.wikipedia.org/xxx browser: firefox selenium: host: ondemand.saucelabs.com port: 80 browser: > { "username": "name", "access-key": "APIkey", "browser": "firefox", "browser-version": "7", "os": "Windows 2003", "name": "Testing Selenium with Behat" }
  • 51. Running on Sauce ● exec with: – behat -c sauce.yml ● View result video of this job: – http://snipurl.com/21huj12 ● reports generate in 'report/report.html'
  • 52. Testing Javascript ● Not posible on Headless Browser – Goutte ● Javascript element interaction – Symfony 2 webdriver – Selenium2
  • 53. Mink Login Feature Exercise ● Mink + Selenium server ● Download Selenium Server – http://seleniumhq.org/download/ ● Get Feature description – git clone git@github.com:marcosQuesada/Login-Workshop-Exercise.git ● Run login Feature ● Do what you want …. but Pass it again
  • 54. Conclusion ● Behat features are meaningful ● Behat is Driven Development ● Behat is complementary to TDD and Unit testing ● Best approach to service assurance ● Let's use it now!
  • 55. References ● Mockery: https://github.com/padraic/mockery ● Behat: http://behat.org/ ● Mink: http://mink.behat.org/
  • 56. Workshop Links ● Behat PHP Base – https://github.com/marcosQuesada/Behat-Base.git ● Symfony 2 Behat Base – https://github.com/marcosQuesada/Symfony2-Behat-Base ● Workshop Features – https://github.com/marcosQuesada/API-Workshop-Exercise.git – https://github.com/marcosQuesada/Login-Workshop-Exercise ● Mockery Examples – https://github.com/marcosQuesada/MockerySf2 ● My Exercise Solutions – https://github.com/marcosQuesada/Api-Behat-Testing – https://github.com/marcosQuesada/Behat-Login-Exercise
  • 57. Thank you! Twitter: @marcos_quesada Linkedin: marcosquesada marcos.quesadas@gmail.com

Editor's Notes

  1. http://docs.behat.org/guides/4.context.html
  2. http://docs.behat.org/guides/3.hooks.html
  3. http://docs.behat.org/cookbook/behat_and_mink.html
  4. http://docs.behat.org/cookbook/behat_and_mink.html