SlideShare a Scribd company logo
1 of 44
Download to read offline
ACCEPTANCE TESTING IN PHP
WITH
CODECEPTION
TECHMEETUP EDINBURGH JANUARY
2016
By / - 13/01/2016Thomas Dutrion @tdutrion
ABOUT ME
Founder & Developer / web architect at
Working with PHP since 2003
Doing my best to work properly!
Engineor
SCOTLAND PHP
Aberdeen (1st Wednesday)
Edinburgh (3rd Tuesday)
Glasgow (3rd Tuesday)
Dundee (3rd Thursday)
https://www.scotlandphp.co.uk
MODERN PHP:
INDUSTRIALISATION
PHP is mature (object oriented, namespaces...).
PHP has a large community.
PHP has a large ecosystem.
WHY LARGE CORPORATION AREN'T
USING IT MORE OFTEN?
TESTABILITY
WHAT CAN WE TEST?
Unit testing
Integration testing
Functional testing
Acceptance testing
Mutation testing
...
WHAT CAN WE CHARGE FOR?
Unit testing (sometimes)
Integration testing (occasionnaly)
Functional testing (occasionnaly)
Acceptance testing (sometimes)
Mutation testing (rarely)
UNIT TESTING
Small units of isolated code (SOLID)
Takes time to write and update
Perfect for critical processes in your application
INTEGRATION TESTING
Test larger units of code together
Does not give specific details to find a bug
Less expensive (less tests)
ACCEPTANCE TESTING
High level testing (as a user)
Client point of view
Less code, easier to implement
Only test final result
Can also be used in business to prove the project
completion
CODECEPTION
ONE TOOL, MULTIPLE TESTING TYPES
GENERAL INTRODUCTION
HISTORY
Started in 2011
First stable January 2012
Currently 2.1.5
4677 commits yesterday night (4267 in October*)
322 contributors yesterday (295 in October*)
*same talk in October last year for DundeePHP
GENERAL INTRODUCTION
PROBLEM SOLVED
Bridge between different testing types
No other languages required (for php developers)
Extensible
Covers all the major PHP framework
LET'S GET INTO IT...
PHP 5.4 MINIMUM (USE AT LEAST 5.6 ANYWAYS!)
PHP supported versions
YOU ALREADY KNOW IT!
OR NOT, BUT YOU SHOULD HAVE A LOOK AT THESE
TOOLS
Based on recommended and proven tools
/ (optional)
...
PHPUnit
Symfony browserkit
Selenium PhantomJS
YOU ALREADY KNOW IT!
Test suites are written in PHP.
You can test websites created in any language (as you are
only testing the result)
ACCEPTANCE TESTING 101
FOLLOW THE QUICKSTART!
1. Install codeception (prefer using composer, globally or
in dev only)
2. Bootstrap (directories and files structure, basic
configuration)
3. Generate acceptance testing
4. Write tests
5. And run!
http://codeception.com/quickstart
...
INSTALL (WITH COMPOSER)
$ composer require "codeception/codeception:*"
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing symfony/polyfill-mbstring (v1.0.1)
Loading from cache
- Installing phpunit/phpunit (4.8.21)
Loading from cache
- Installing codeception/codeception (2.1.5)
Downloading: 100%
Writing lock file
Generating autoload files
DIRECTORY CONTENT
$ tree -I vendor
.
├── composer.json
└── composer.lock
Option -I to remove the vendor folder from the display as
it contains only third party libraries.
BOOTSTRAP
$ php vendor/bin/codecept bootstrap
Initializing Codeception in /presentations/2016-01-13-Codeception-Techmeetup-
File codeception.yml created <- global configuration
tests/unit created <- unit tests
tests/unit.suite.yml written <- unit tests suite configuration
tests/functional created <- functional tests
tests/functional.suite.yml written <- functional tests suite configuration
tests/acceptance created <- acceptance tests
tests/acceptance.suite.yml written <- acceptance tests suite configuration
---
tests/_bootstrap.php written <- global bootstrap file
Building initial Tester classes
Building Actor classes for suites: acceptance, functional, unit
-> AcceptanceTesterActions.php generated successfully. 0 methods added
AcceptanceTester includes modules: PhpBrowser, HelperAcceptance
DIRECTORY CONTENT
$ tree -I vendor
.
├── codeception.yml
├── composer.json
├── composer.lock
└── tests
├── _bootstrap.php
├── _data
│   └── dump.sql
├── _envs
├── _output
├── _support
│   ├── AcceptanceTester.php
│   ├── FunctionalTester.php
│   ├── Helper
│   │   ├── Acceptance.php
│   │   ├── Functional.php
Option -I to remove the vendor folder from the display as
it contains only third party libraries.
TEST GENERATION
$ vendor/bin/codecept generate:cept acceptance Welcome
Test was created in /presentations/2016-01-13-Codeception-Techmeetup-Edinburg
Generates tests/acceptance/WelcomeCept.php:
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('perform actions and see result');
WRITE TESTS
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that Edinburgh is listed on the homepage');
$I->amOnPage('/');
$I->see('Edinburgh');
tests/acceptance/WelcomeCept.php
UPDATE CONFIGURATION
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: http://techmeetup.co.uk/
- HelperAcceptance
tests/acceptance.suite.yml
BASIC EXAMPLE RESULTS (PASS)
$ vendor/bin/codecept run
Codeception PHP Testing Framework v2.1.5
Powered by PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
Acceptance Tests (1) --------------------------------------------
Ensure that frontpage works (WelcomeCept) Ok
-----------------------------------------------------------------
Functional Tests (0) --------------------------------------------
Unit Tests (0) --------------------------------------------------
Time: 630 ms, Memory: 10.00Mb
OK (1 test, 1 assertion)
ADD TEST
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that Edinburgh is listed on the homepage');
$I->amOnPage('/');
$I->see('Edinburgh');
$I->see('This does not appear on the page');
tests/acceptance/WelcomeCept.php
BASIC EXAMPLE RESULTS (FAIL)
$ vendor/bin/codecept run
Codeception PHP Testing Framework v2.1.5
Powered by PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
Acceptance Tests (1) ---------------------------------------------
Ensure that frontpage works (WelcomeCept) Fail
------------------------------------------------------------------
Functional Tests (0) ---------------------------------------------
Unit Tests (0) ---------------------------------------------------
Time: 605 ms, Memory: 10.00Mb
BASIC EXAMPLE RESULTS (FAIL)
There was 1 failure:
---------
1) Failed to ensure that frontpage works in WelcomeCept (tests/acceptance/Wel
Step I see "This does not appear on the page"
Fail Failed asserting that /
-->
TechMeetup - Home
Tech Meetup
About
Videos
Blog
Calendar
TechMeetup is a monthly excuse for developers and the tech communit
[Content too long to display. See complete response in '_output' directory]
--> contains "this does not appear on the page".
BASIC EXAMPLE RESULTS (FAIL)
Scenario Steps:
3. $I->see("This does not appear on the page") at tests/acceptance/WelcomeCe
2. $I->see("Edinburgh") at tests/acceptance/WelcomeCept.php:5
1. $I->amOnPage("/") at tests/acceptance/WelcomeCept.php:4
FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
CHANGE TESTS
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that Edinburgh is listed on the homepage');
$I->amOnPage('/');
$I->see('Edinburgh');
$I->click('Edinburgh');
$I->amOnPage('/edinburgh.html');
$I->see('2nd Wed of month');
tests/acceptance/WelcomeCept.php
RESULTS
$ vendor/bin/codecept run
Codeception PHP Testing Framework v2.1.5
Powered by PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
Acceptance Tests (1) --------------------------------------------
Ensure that frontpage works (WelcomeCept) Ok
-----------------------------------------------------------------
Functional Tests (0) --------------------------------------------
Unit Tests (0) --------------------------------------------------
Time: 834 ms, Memory: 10.00Mb
OK (1 test, 2 assertions)
MODERN FRONTEND ISSUES
PROBLEM:
Since 2005, AJAX is everywhere (XmlHttpRequest)
New architecture: MVVM javascript in front,
PHP/node… in back
Testing problem: PHPBrowser / Curl can not read
javascript modifications.
SOLUTION 1:
USE SELENIUM DRIVER AND DELAYS
Simple configuration (see the documentation).
Looks good when showing off to your client!
composer require --dev "netwing/selenium-server-standalone:^2.46"
SOLUTION 1:
USE SELENIUM DRIVER AND DELAYS
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- HelperAcceptance
config:
WebDriver:
url: 'https://phpmentoring.org'
browser: 'firefox'
window_size: 1024x768
SOLUTION 1:
USE SELENIUM DRIVER AND DELAYS
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that tdutrion is displayed as a mentor');
$I->amOnPage('/mentors');
$I->wait(1);
$I->see('Thomas Dutrion');
SOLUTION 1:
USE SELENIUM DRIVER AND DELAYS
java -jar vendor/bin/selenium-server-standalone-2.46.0.jar
vendor/bin/codecept run
SOLUTION 2:
USE SOMETHING MORE APPROPRIATE?
Google recommends , but other exist
( , ).
Karma
Nightwatch.js Jasmine
PROBLEM 2:
I can not use Java and Firefox on my continuous
integration server!
(Who would do that?)
SOLUTION:
USE A HEADLESS BROWSER
(PHANTOMJS)
Just a configuration again, try at home!
QUESTIONS?
THANKS FOR HAVING ME!
Special thanks to / reading recommendation:
Jeremy Coates ( ) for
PHPNW ( ), great PHP group that made me discover
Codeception
All of you for your patience and supporting me!
Techmeetup ( ) to let me talk here
@phpcodemonkey Testing with codeception
@phpnw
@techmeetup
Please rate and comment this talk on SlideShare: http://goo.gl/068L56

More Related Content

What's hot

Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in YiiIlPeach
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in YiiIlPeach
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Joe Ferguson
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Cogapp
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Joe Ferguson
 
Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)Adam Štipák
 
Automation using Javascript
Automation using JavascriptAutomation using Javascript
Automation using Javascriptkhanhdang1214
 
Advanced Selenium Workshop
Advanced Selenium WorkshopAdvanced Selenium Workshop
Advanced Selenium WorkshopClever Moe
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web ApplicationsSeth McLaughlin
 
Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011hugs
 
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Practical Tips & Tricks for Selenium Test Automation - Dave HaeffnerPractical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Practical Tips & Tricks for Selenium Test Automation - Dave HaeffnerApplitools
 
Selenium Basics Tutorial
Selenium Basics TutorialSelenium Basics Tutorial
Selenium Basics TutorialClever Moe
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravelDerek Binkley
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: DemystifiedSeth McLaughlin
 
Introduction to Selenium
Introduction to SeleniumIntroduction to Selenium
Introduction to Seleniumrohitnayak
 
Selenium webdriver interview questions and answers
Selenium webdriver interview questions and answersSelenium webdriver interview questions and answers
Selenium webdriver interview questions and answersITeLearn
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using SeleniumNaresh Chintalcheru
 

What's hot (20)

Codeception
CodeceptionCodeception
Codeception
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in Yii
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015
 
Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)
 
Integration Testing in Python
Integration Testing in PythonIntegration Testing in Python
Integration Testing in Python
 
Automation using Javascript
Automation using JavascriptAutomation using Javascript
Automation using Javascript
 
Advanced Selenium Workshop
Advanced Selenium WorkshopAdvanced Selenium Workshop
Advanced Selenium Workshop
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web Applications
 
Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011
 
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Practical Tips & Tricks for Selenium Test Automation - Dave HaeffnerPractical Tips & Tricks for Selenium Test Automation - Dave Haeffner
Practical Tips & Tricks for Selenium Test Automation - Dave Haeffner
 
Selenium Basics Tutorial
Selenium Basics TutorialSelenium Basics Tutorial
Selenium Basics Tutorial
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravel
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
 
Introduction to Selenium
Introduction to SeleniumIntroduction to Selenium
Introduction to Selenium
 
Selenium webdriver interview questions and answers
Selenium webdriver interview questions and answersSelenium webdriver interview questions and answers
Selenium webdriver interview questions and answers
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 

Similar to Acceptance testing in php with Codeception - Techmeetup Edinburgh

Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 
Simple tools to fight bigger quality battle
Simple tools to fight bigger quality battleSimple tools to fight bigger quality battle
Simple tools to fight bigger quality battleAnand Ramdeo
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesPavol Pitoňák
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsDECK36
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.Javier López
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP applicationJavier López
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Roberto Franchini
 
OSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ InfosectrainOSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ InfosectrainInfosecTrain
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayAnne Nicolas
 
Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsArtur Babyuk
 
Getting started with CFEngine - Webinar
Getting started with CFEngine - WebinarGetting started with CFEngine - Webinar
Getting started with CFEngine - WebinarCFEngine
 
Kirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for AutomatizationKirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for AutomatizationSergey Arkhipov
 
Getting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated VersionGetting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated VersionCFEngine
 
Improve your Java Environment with Docker
Improve your Java Environment with DockerImprove your Java Environment with Docker
Improve your Java Environment with DockerHanoiJUG
 
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaCloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaAmazon Web Services
 
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
 
Joget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow v6 Training Slides - 16 - Preparing Development EnvironmentJoget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow v6 Training Slides - 16 - Preparing Development EnvironmentJoget Workflow
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Fabrice Bernhard
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesOtto Kekäläinen
 
The Emergence of Choice in the .NET Ecosystem
The Emergence of Choice in the .NET EcosystemThe Emergence of Choice in the .NET Ecosystem
The Emergence of Choice in the .NET EcosystemJames Avery
 

Similar to Acceptance testing in php with Codeception - Techmeetup Edinburgh (20)

Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Simple tools to fight bigger quality battle
Simple tools to fight bigger quality battleSimple tools to fight bigger quality battle
Simple tools to fight bigger quality battle
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile Devices
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
 
OSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ InfosectrainOSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ Infosectrain
 
Embedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops wayEmbedded Recipes 2019 - Testing firmware the devops way
Embedded Recipes 2019 - Testing firmware the devops way
 
Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP Basics
 
Getting started with CFEngine - Webinar
Getting started with CFEngine - WebinarGetting started with CFEngine - Webinar
Getting started with CFEngine - Webinar
 
Kirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for AutomatizationKirill Rozin - Practical Wars for Automatization
Kirill Rozin - Practical Wars for Automatization
 
Getting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated VersionGetting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated Version
 
Improve your Java Environment with Docker
Improve your Java Environment with DockerImprove your Java Environment with Docker
Improve your Java Environment with Docker
 
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaCloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
 
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...
 
Joget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow v6 Training Slides - 16 - Preparing Development EnvironmentJoget Workflow v6 Training Slides - 16 - Preparing Development Environment
Joget Workflow v6 Training Slides - 16 - Preparing Development Environment
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themes
 
The Emergence of Choice in the .NET Ecosystem
The Emergence of Choice in the .NET EcosystemThe Emergence of Choice in the .NET Ecosystem
The Emergence of Choice in the .NET Ecosystem
 

Recently uploaded

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

Acceptance testing in php with Codeception - Techmeetup Edinburgh

  • 1. ACCEPTANCE TESTING IN PHP WITH CODECEPTION TECHMEETUP EDINBURGH JANUARY 2016 By / - 13/01/2016Thomas Dutrion @tdutrion
  • 2. ABOUT ME Founder & Developer / web architect at Working with PHP since 2003 Doing my best to work properly! Engineor
  • 3. SCOTLAND PHP Aberdeen (1st Wednesday) Edinburgh (3rd Tuesday) Glasgow (3rd Tuesday) Dundee (3rd Thursday) https://www.scotlandphp.co.uk
  • 4. MODERN PHP: INDUSTRIALISATION PHP is mature (object oriented, namespaces...). PHP has a large community. PHP has a large ecosystem. WHY LARGE CORPORATION AREN'T USING IT MORE OFTEN?
  • 6. WHAT CAN WE TEST? Unit testing Integration testing Functional testing Acceptance testing Mutation testing ...
  • 7. WHAT CAN WE CHARGE FOR? Unit testing (sometimes) Integration testing (occasionnaly) Functional testing (occasionnaly) Acceptance testing (sometimes) Mutation testing (rarely)
  • 8. UNIT TESTING Small units of isolated code (SOLID) Takes time to write and update Perfect for critical processes in your application
  • 9. INTEGRATION TESTING Test larger units of code together Does not give specific details to find a bug Less expensive (less tests)
  • 10. ACCEPTANCE TESTING High level testing (as a user) Client point of view Less code, easier to implement Only test final result Can also be used in business to prove the project completion
  • 12. GENERAL INTRODUCTION HISTORY Started in 2011 First stable January 2012 Currently 2.1.5 4677 commits yesterday night (4267 in October*) 322 contributors yesterday (295 in October*) *same talk in October last year for DundeePHP
  • 13. GENERAL INTRODUCTION PROBLEM SOLVED Bridge between different testing types No other languages required (for php developers) Extensible Covers all the major PHP framework
  • 14. LET'S GET INTO IT...
  • 15. PHP 5.4 MINIMUM (USE AT LEAST 5.6 ANYWAYS!) PHP supported versions
  • 16. YOU ALREADY KNOW IT! OR NOT, BUT YOU SHOULD HAVE A LOOK AT THESE TOOLS Based on recommended and proven tools / (optional) ... PHPUnit Symfony browserkit Selenium PhantomJS
  • 17. YOU ALREADY KNOW IT! Test suites are written in PHP. You can test websites created in any language (as you are only testing the result)
  • 19. FOLLOW THE QUICKSTART! 1. Install codeception (prefer using composer, globally or in dev only) 2. Bootstrap (directories and files structure, basic configuration) 3. Generate acceptance testing 4. Write tests 5. And run! http://codeception.com/quickstart
  • 20. ... INSTALL (WITH COMPOSER) $ composer require "codeception/codeception:*" ./composer.json has been created Loading composer repositories with package information Updating dependencies (including require-dev) - Installing symfony/polyfill-mbstring (v1.0.1) Loading from cache - Installing phpunit/phpunit (4.8.21) Loading from cache - Installing codeception/codeception (2.1.5) Downloading: 100% Writing lock file Generating autoload files
  • 21. DIRECTORY CONTENT $ tree -I vendor . ├── composer.json └── composer.lock Option -I to remove the vendor folder from the display as it contains only third party libraries.
  • 22. BOOTSTRAP $ php vendor/bin/codecept bootstrap Initializing Codeception in /presentations/2016-01-13-Codeception-Techmeetup- File codeception.yml created <- global configuration tests/unit created <- unit tests tests/unit.suite.yml written <- unit tests suite configuration tests/functional created <- functional tests tests/functional.suite.yml written <- functional tests suite configuration tests/acceptance created <- acceptance tests tests/acceptance.suite.yml written <- acceptance tests suite configuration --- tests/_bootstrap.php written <- global bootstrap file Building initial Tester classes Building Actor classes for suites: acceptance, functional, unit -> AcceptanceTesterActions.php generated successfully. 0 methods added AcceptanceTester includes modules: PhpBrowser, HelperAcceptance
  • 23. DIRECTORY CONTENT $ tree -I vendor . ├── codeception.yml ├── composer.json ├── composer.lock └── tests ├── _bootstrap.php ├── _data │   └── dump.sql ├── _envs ├── _output ├── _support │   ├── AcceptanceTester.php │   ├── FunctionalTester.php │   ├── Helper │   │   ├── Acceptance.php │   │   ├── Functional.php Option -I to remove the vendor folder from the display as it contains only third party libraries.
  • 24. TEST GENERATION $ vendor/bin/codecept generate:cept acceptance Welcome Test was created in /presentations/2016-01-13-Codeception-Techmeetup-Edinburg Generates tests/acceptance/WelcomeCept.php: <?php $I = new AcceptanceTester($scenario); $I->wantTo('perform actions and see result');
  • 25. WRITE TESTS <?php $I = new AcceptanceTester($scenario); $I->wantTo('ensure that Edinburgh is listed on the homepage'); $I->amOnPage('/'); $I->see('Edinburgh'); tests/acceptance/WelcomeCept.php
  • 26. UPDATE CONFIGURATION # Codeception Test Suite Configuration # # Suite for acceptance tests. # Perform tests in browser using the WebDriver or PhpBrowser. # If you need both WebDriver and PHPBrowser tests - create a separate suite. class_name: AcceptanceTester modules: enabled: - PhpBrowser: url: http://techmeetup.co.uk/ - HelperAcceptance tests/acceptance.suite.yml
  • 27. BASIC EXAMPLE RESULTS (PASS) $ vendor/bin/codecept run Codeception PHP Testing Framework v2.1.5 Powered by PHPUnit 4.8.21 by Sebastian Bergmann and contributors. Acceptance Tests (1) -------------------------------------------- Ensure that frontpage works (WelcomeCept) Ok ----------------------------------------------------------------- Functional Tests (0) -------------------------------------------- Unit Tests (0) -------------------------------------------------- Time: 630 ms, Memory: 10.00Mb OK (1 test, 1 assertion)
  • 28. ADD TEST <?php $I = new AcceptanceTester($scenario); $I->wantTo('ensure that Edinburgh is listed on the homepage'); $I->amOnPage('/'); $I->see('Edinburgh'); $I->see('This does not appear on the page'); tests/acceptance/WelcomeCept.php
  • 29. BASIC EXAMPLE RESULTS (FAIL) $ vendor/bin/codecept run Codeception PHP Testing Framework v2.1.5 Powered by PHPUnit 4.8.21 by Sebastian Bergmann and contributors. Acceptance Tests (1) --------------------------------------------- Ensure that frontpage works (WelcomeCept) Fail ------------------------------------------------------------------ Functional Tests (0) --------------------------------------------- Unit Tests (0) --------------------------------------------------- Time: 605 ms, Memory: 10.00Mb
  • 30. BASIC EXAMPLE RESULTS (FAIL) There was 1 failure: --------- 1) Failed to ensure that frontpage works in WelcomeCept (tests/acceptance/Wel Step I see "This does not appear on the page" Fail Failed asserting that / --> TechMeetup - Home Tech Meetup About Videos Blog Calendar TechMeetup is a monthly excuse for developers and the tech communit [Content too long to display. See complete response in '_output' directory] --> contains "this does not appear on the page".
  • 31. BASIC EXAMPLE RESULTS (FAIL) Scenario Steps: 3. $I->see("This does not appear on the page") at tests/acceptance/WelcomeCe 2. $I->see("Edinburgh") at tests/acceptance/WelcomeCept.php:5 1. $I->amOnPage("/") at tests/acceptance/WelcomeCept.php:4 FAILURES! Tests: 1, Assertions: 2, Failures: 1.
  • 32. CHANGE TESTS <?php $I = new AcceptanceTester($scenario); $I->wantTo('ensure that Edinburgh is listed on the homepage'); $I->amOnPage('/'); $I->see('Edinburgh'); $I->click('Edinburgh'); $I->amOnPage('/edinburgh.html'); $I->see('2nd Wed of month'); tests/acceptance/WelcomeCept.php
  • 33. RESULTS $ vendor/bin/codecept run Codeception PHP Testing Framework v2.1.5 Powered by PHPUnit 4.8.21 by Sebastian Bergmann and contributors. Acceptance Tests (1) -------------------------------------------- Ensure that frontpage works (WelcomeCept) Ok ----------------------------------------------------------------- Functional Tests (0) -------------------------------------------- Unit Tests (0) -------------------------------------------------- Time: 834 ms, Memory: 10.00Mb OK (1 test, 2 assertions)
  • 35. PROBLEM: Since 2005, AJAX is everywhere (XmlHttpRequest) New architecture: MVVM javascript in front, PHP/node… in back Testing problem: PHPBrowser / Curl can not read javascript modifications.
  • 36. SOLUTION 1: USE SELENIUM DRIVER AND DELAYS Simple configuration (see the documentation). Looks good when showing off to your client! composer require --dev "netwing/selenium-server-standalone:^2.46"
  • 37. SOLUTION 1: USE SELENIUM DRIVER AND DELAYS # Codeception Test Suite Configuration # # Suite for acceptance tests. # Perform tests in browser using the WebDriver or PhpBrowser. # If you need both WebDriver and PHPBrowser tests - create a separate suite. class_name: AcceptanceTester modules: enabled: - WebDriver - HelperAcceptance config: WebDriver: url: 'https://phpmentoring.org' browser: 'firefox' window_size: 1024x768
  • 38. SOLUTION 1: USE SELENIUM DRIVER AND DELAYS <?php $I = new AcceptanceTester($scenario); $I->wantTo('ensure that tdutrion is displayed as a mentor'); $I->amOnPage('/mentors'); $I->wait(1); $I->see('Thomas Dutrion');
  • 39. SOLUTION 1: USE SELENIUM DRIVER AND DELAYS java -jar vendor/bin/selenium-server-standalone-2.46.0.jar vendor/bin/codecept run
  • 40. SOLUTION 2: USE SOMETHING MORE APPROPRIATE? Google recommends , but other exist ( , ). Karma Nightwatch.js Jasmine
  • 41. PROBLEM 2: I can not use Java and Firefox on my continuous integration server! (Who would do that?)
  • 42. SOLUTION: USE A HEADLESS BROWSER (PHANTOMJS) Just a configuration again, try at home!
  • 44. THANKS FOR HAVING ME! Special thanks to / reading recommendation: Jeremy Coates ( ) for PHPNW ( ), great PHP group that made me discover Codeception All of you for your patience and supporting me! Techmeetup ( ) to let me talk here @phpcodemonkey Testing with codeception @phpnw @techmeetup Please rate and comment this talk on SlideShare: http://goo.gl/068L56