SlideShare a Scribd company logo
AUTOMATED TESTING WITH
CODECEPTION
PHP automated testing framework	

Jonathan Lau

Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
MOTIVATION + BIO
•

Quick start guide for codeception	


•

Experience with running it in a Cake based project	


•

Introduce it as a alternative choice

Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
TEST STRATEGY
What do we use these days?
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
WAYS TO TEST
•

Unit test

•

Functional test

•

White box testing	


•

•

Full knowledge of the code
base	


Knowledge of input and
expected output	


•

No browser emulation	


•

!

Run script during build /
check out	


•

Acceptance test
•

Yes, still need this for sanity
sake

Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
EFFORT VS RETURN
•

•

Unit tests are easy to write
but it can’t cover integration
issue	

Functional / acceptance
tests can cover the end to
end behavior but it can take
a while to write and some
effort to maintain

Maintenance effort
Acceptance test

Functional test
Unit test

Coverage

Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
ACCEPTANCE TEST
Let the robot do the clicking
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
ACCEPTANCE TEST
•

Browser emulator: Selenum or Mink	


•

Select on-screen elements by text or path	


•

Supported actions: click, enter text, drag drop etc.	


•

Coverage can be an issue	


•

Really SLOW
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
EXAMPLE CODE
<?php	

$I = new WebGuy($scenario);	

$I->amOnPage('/');	

$I->click('Sign Up');	

$I->submitForm('#signup', array('username' => 'MilesDavis', 'email' =>
'miles@davis.com'));	

$I->see('Thank you for Signing Up!');	

?>
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
FUNCTIONAL TEST
•

Very similar concept as acceptance test	


•

No browser emulation 	


•

Emulate the actual web request instead	


•

Might need hook into the framework to introduce a test
mode.	


•

Can’t test javascript / AJAX
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
EXAMPLE CODE
<?php	

$I = new TestGuy($scenario);	

$I->amOnPage('/');	

$I->click('Sign Up');	

$I->submitForm('#signup', array('username' => 'MilesDavis', 'email' => 'miles@davis.com'));	

$I->see('Thank you for Signing Up!');	

$I->seeEmailSent('miles@davis.com', 'Thank you for registration');	

$I->seeInDatabase('users', array('email' => 'miles@davis.com'));	

?>
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
UNIT TEST
•

Friendly only to developer	


•

Running the test subject in isolation and surrounding pieces are
stubbed out	


•

It’s good for validating logic correctness 	


•

Can’t validate integration issues	


•

Built on top of PHP Unit and has more tooling to help write test
faster
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
EXAMPLE CODE
<?php	

// we are testing the public method of User class.	

$I = new CodeGuy($scenario);	

$I->testMethod('User.update');	

$I->haveStubClass($unit = Stub::make('User'));	

$I->dontSeeInDatabase('users', array('id' => 1, 'username' => 'miles'));	

$I->executeTestedMethodOn($unit, 1, array('username' => 'miles'));	

$I->seeMethodInvoked($unit, 'save');	

$I->seeInDatabase('users', array('id' => 1, 'username' => 'miles'));	

?>
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
GENERAL PITFALLS
•

Javascript pop up box	


•

Drag and drop - takes a bit more work to get it to
work	


•

Delay tuning - variance in the latency on the web
servers	


•

Browser session is refreshed between test files
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
WHAT WORKS FOR US
•

Integration risk is always
larger than algorithmic
correctness	


•

Automating acceptance test
is a huge win	


•

Automating functional test
should be next	


•

Unit test… meh…
Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
KILL BUGS
LIKE THE
TERRAINS
Good luck and thanks	

!

jon@smokehousesoftware.com
!

Contributors: Kenneth Chiu	


Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com

More Related Content

What's hot (20)

PPTX
CI / CD w/ Codeception
Tudor Barbu
 
PPTX
Test automation with php codeception
buddhieash
 
PDF
PHP Unit Testing in Yii
IlPeach
 
PDF
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
PDF
Testing PHP with Codeception
John Paul Ada
 
PDF
From Good to Great: Functional and Acceptance Testing in WordPress.
David Aguilera
 
PDF
Unit-testing and E2E testing in JS
Michael Haberman
 
PDF
Mastering Test Automation: How to Use Selenium Successfully
Applitools
 
ODP
Integration Testing in Python
Panoptic Development, Inc.
 
DOCX
Automation Frame works Instruction Sheet
vodQA
 
PPTX
Testing with laravel
Derek Binkley
 
PDF
Codeception: introduction to php testing (v2 - Aberdeen php)
Engineor
 
PDF
Testing with Codeception (Webelement #30)
Adam Štipák
 
PDF
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Applitools
 
PPTX
Laravel Unit Testing
Dr. Syed Hassan Amin
 
PDF
Selenium Basics Tutorial
Clever Moe
 
PDF
Integration testing - A&BP CC
JWORKS powered by Ordina
 
PDF
Unit testing - A&BP CC
JWORKS powered by Ordina
 
PDF
Front-End Testing: Demystified
Seth McLaughlin
 
PDF
How To Use Selenium Successfully
Dave Haeffner
 
CI / CD w/ Codeception
Tudor Barbu
 
Test automation with php codeception
buddhieash
 
PHP Unit Testing in Yii
IlPeach
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
Testing PHP with Codeception
John Paul Ada
 
From Good to Great: Functional and Acceptance Testing in WordPress.
David Aguilera
 
Unit-testing and E2E testing in JS
Michael Haberman
 
Mastering Test Automation: How to Use Selenium Successfully
Applitools
 
Integration Testing in Python
Panoptic Development, Inc.
 
Automation Frame works Instruction Sheet
vodQA
 
Testing with laravel
Derek Binkley
 
Codeception: introduction to php testing (v2 - Aberdeen php)
Engineor
 
Testing with Codeception (Webelement #30)
Adam Štipák
 
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Applitools
 
Laravel Unit Testing
Dr. Syed Hassan Amin
 
Selenium Basics Tutorial
Clever Moe
 
Integration testing - A&BP CC
JWORKS powered by Ordina
 
Unit testing - A&BP CC
JWORKS powered by Ordina
 
Front-End Testing: Demystified
Seth McLaughlin
 
How To Use Selenium Successfully
Dave Haeffner
 

Similar to Codeception (20)

PDF
Testing mit Codeception: Full-stack testing PHP framework
SusannSgorzaly
 
PDF
Variety of automated tests
Артём Курапов
 
PPTX
Codeception @ New Business Dept Adira Finance
Fachrul Choliluddin
 
PPTX
Test in action – week 1
Yi-Huan Chan
 
PDF
PHPunit and you
markstory
 
ZIP
Test
Eddie Kao
 
PDF
Your code are my tests
Michelangelo van Dam
 
PPTX
Automated Testing
Speed FC
 
PPTX
Testy dymne, integracyjne i jednostkowe w Laravel
Laravel Poland MeetUp
 
PPTX
One to rule them all
Antonio Robres Turon
 
PPTX
Regression Testing with Symfony
Joachim Unger
 
KEY
Developer testing 201: When to Mock and When to Integrate
LB Denker
 
PDF
Mykhailo Bodnarchuk "The history of the Codeception project"
Fwdays
 
PDF
Intro to PHP Testing
Ran Mizrahi
 
KEY
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
 
PPT
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
PPT
Test Driven Development with PHPUnit
Mindfire Solutions
 
PPTX
Getting started-php unit
mfrost503
 
PPT
Unit testing
davidahaskins
 
KEY
Developer testing 101: Become a Testing Fanatic
LB Denker
 
Testing mit Codeception: Full-stack testing PHP framework
SusannSgorzaly
 
Variety of automated tests
Артём Курапов
 
Codeception @ New Business Dept Adira Finance
Fachrul Choliluddin
 
Test in action – week 1
Yi-Huan Chan
 
PHPunit and you
markstory
 
Test
Eddie Kao
 
Your code are my tests
Michelangelo van Dam
 
Automated Testing
Speed FC
 
Testy dymne, integracyjne i jednostkowe w Laravel
Laravel Poland MeetUp
 
One to rule them all
Antonio Robres Turon
 
Regression Testing with Symfony
Joachim Unger
 
Developer testing 201: When to Mock and When to Integrate
LB Denker
 
Mykhailo Bodnarchuk "The history of the Codeception project"
Fwdays
 
Intro to PHP Testing
Ran Mizrahi
 
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
 
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
Test Driven Development with PHPUnit
Mindfire Solutions
 
Getting started-php unit
mfrost503
 
Unit testing
davidahaskins
 
Developer testing 101: Become a Testing Fanatic
LB Denker
 
Ad

Recently uploaded (20)

PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Digital Circuits, important subject in CS
contactparinay1
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Ad

Codeception

  • 1. AUTOMATED TESTING WITH CODECEPTION PHP automated testing framework Jonathan Lau Smokehouse Software | Jonathan Lau | [email protected]
  • 2. MOTIVATION + BIO • Quick start guide for codeception • Experience with running it in a Cake based project • Introduce it as a alternative choice Smokehouse Software | Jonathan Lau | [email protected]
  • 3. TEST STRATEGY What do we use these days? Smokehouse Software | Jonathan Lau | [email protected]
  • 4. WAYS TO TEST • Unit test • Functional test • White box testing • • Full knowledge of the code base Knowledge of input and expected output • No browser emulation • ! Run script during build / check out • Acceptance test • Yes, still need this for sanity sake Smokehouse Software | Jonathan Lau | [email protected]
  • 5. EFFORT VS RETURN • • Unit tests are easy to write but it can’t cover integration issue Functional / acceptance tests can cover the end to end behavior but it can take a while to write and some effort to maintain Maintenance effort Acceptance test Functional test Unit test Coverage Smokehouse Software | Jonathan Lau | [email protected]
  • 6. ACCEPTANCE TEST Let the robot do the clicking Smokehouse Software | Jonathan Lau | [email protected]
  • 7. ACCEPTANCE TEST • Browser emulator: Selenum or Mink • Select on-screen elements by text or path • Supported actions: click, enter text, drag drop etc. • Coverage can be an issue • Really SLOW Smokehouse Software | Jonathan Lau | [email protected]
  • 8. EXAMPLE CODE <?php $I = new WebGuy($scenario); $I->amOnPage('/'); $I->click('Sign Up'); $I->submitForm('#signup', array('username' => 'MilesDavis', 'email' => '[email protected]')); $I->see('Thank you for Signing Up!'); ?> Smokehouse Software | Jonathan Lau | [email protected]
  • 9. FUNCTIONAL TEST • Very similar concept as acceptance test • No browser emulation • Emulate the actual web request instead • Might need hook into the framework to introduce a test mode. • Can’t test javascript / AJAX Smokehouse Software | Jonathan Lau | [email protected]
  • 10. EXAMPLE CODE <?php $I = new TestGuy($scenario); $I->amOnPage('/'); $I->click('Sign Up'); $I->submitForm('#signup', array('username' => 'MilesDavis', 'email' => '[email protected]')); $I->see('Thank you for Signing Up!'); $I->seeEmailSent('[email protected]', 'Thank you for registration'); $I->seeInDatabase('users', array('email' => '[email protected]')); ?> Smokehouse Software | Jonathan Lau | [email protected]
  • 11. UNIT TEST • Friendly only to developer • Running the test subject in isolation and surrounding pieces are stubbed out • It’s good for validating logic correctness • Can’t validate integration issues • Built on top of PHP Unit and has more tooling to help write test faster Smokehouse Software | Jonathan Lau | [email protected]
  • 12. EXAMPLE CODE <?php // we are testing the public method of User class. $I = new CodeGuy($scenario); $I->testMethod('User.update'); $I->haveStubClass($unit = Stub::make('User')); $I->dontSeeInDatabase('users', array('id' => 1, 'username' => 'miles')); $I->executeTestedMethodOn($unit, 1, array('username' => 'miles')); $I->seeMethodInvoked($unit, 'save'); $I->seeInDatabase('users', array('id' => 1, 'username' => 'miles')); ?> Smokehouse Software | Jonathan Lau | [email protected]
  • 13. GENERAL PITFALLS • Javascript pop up box • Drag and drop - takes a bit more work to get it to work • Delay tuning - variance in the latency on the web servers • Browser session is refreshed between test files Smokehouse Software | Jonathan Lau | [email protected]
  • 14. WHAT WORKS FOR US • Integration risk is always larger than algorithmic correctness • Automating acceptance test is a huge win • Automating functional test should be next • Unit test… meh… Smokehouse Software | Jonathan Lau | [email protected]
  • 15. KILL BUGS LIKE THE TERRAINS Good luck and thanks ! [email protected] ! Contributors: Kenneth Chiu Smokehouse Software | Jonathan Lau | [email protected]