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

PDF
Codeception: introduction to php testing
PDF
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
PDF
Codeception introduction and use in Yii
PPTX
Codeception
PDF
Testing with Codeception
PDF
Acceptance & Functional Testing with Codeception - Devspace 2015
PDF
Codeception presentation
PDF
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Codeception: introduction to php testing
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Codeception introduction and use in Yii
Codeception
Testing with Codeception
Acceptance & Functional Testing with Codeception - Devspace 2015
Codeception presentation
Acceptance testing in php with Codeception - Techmeetup Edinburgh

What's hot (20)

PPTX
CI / CD w/ Codeception
PPTX
Test automation with php codeception
PDF
PHP Unit Testing in Yii
PDF
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
PDF
Testing PHP with Codeception
PDF
From Good to Great: Functional and Acceptance Testing in WordPress.
PDF
Unit-testing and E2E testing in JS
PDF
Mastering Test Automation: How to Use Selenium Successfully
ODP
Integration Testing in Python
DOCX
Automation Frame works Instruction Sheet
PPTX
Testing with laravel
PDF
Codeception: introduction to php testing (v2 - Aberdeen php)
PDF
Testing with Codeception (Webelement #30)
PDF
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
PPTX
Laravel Unit Testing
PDF
Selenium Basics Tutorial
PDF
Integration testing - A&BP CC
PDF
Unit testing - A&BP CC
PDF
Front-End Testing: Demystified
PDF
How To Use Selenium Successfully
CI / CD w/ Codeception
Test automation with php codeception
PHP Unit Testing in Yii
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Testing PHP with Codeception
From Good to Great: Functional and Acceptance Testing in WordPress.
Unit-testing and E2E testing in JS
Mastering Test Automation: How to Use Selenium Successfully
Integration Testing in Python
Automation Frame works Instruction Sheet
Testing with laravel
Codeception: introduction to php testing (v2 - Aberdeen php)
Testing with Codeception (Webelement #30)
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Laravel Unit Testing
Selenium Basics Tutorial
Integration testing - A&BP CC
Unit testing - A&BP CC
Front-End Testing: Demystified
How To Use Selenium Successfully
Ad

Similar to Codeception (20)

PDF
Testing mit Codeception: Full-stack testing PHP framework
PDF
Variety of automated tests
PPTX
Codeception @ New Business Dept Adira Finance
PPTX
Test in action – week 1
PDF
PHPunit and you
ZIP
Test
PDF
Your code are my tests
PPTX
Automated Testing
PPTX
Testy dymne, integracyjne i jednostkowe w Laravel
PPTX
One to rule them all
PPTX
Regression Testing with Symfony
KEY
Developer testing 201: When to Mock and When to Integrate
PDF
Mykhailo Bodnarchuk "The history of the Codeception project"
PDF
Intro to PHP Testing
KEY
Php Unit With Zend Framework Zendcon09
PPT
Unit testing php-unit - phing - selenium_v2
PPT
Test Driven Development with PHPUnit
PPTX
Getting started-php unit
PPT
Unit testing
KEY
Developer testing 101: Become a Testing Fanatic
Testing mit Codeception: Full-stack testing PHP framework
Variety of automated tests
Codeception @ New Business Dept Adira Finance
Test in action – week 1
PHPunit and you
Test
Your code are my tests
Automated Testing
Testy dymne, integracyjne i jednostkowe w Laravel
One to rule them all
Regression Testing with Symfony
Developer testing 201: When to Mock and When to Integrate
Mykhailo Bodnarchuk "The history of the Codeception project"
Intro to PHP Testing
Php Unit With Zend Framework Zendcon09
Unit testing php-unit - phing - selenium_v2
Test Driven Development with PHPUnit
Getting started-php unit
Unit testing
Developer testing 101: Become a Testing Fanatic
Ad

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Modernizing your data center with Dell and AMD
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
PPTX
A Presentation on Artificial Intelligence
PPTX
MYSQL Presentation for SQL database connectivity
NewMind AI Monthly Chronicles - July 2025
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Review of recent advances in non-invasive hemoglobin estimation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Network Security Unit 5.pdf for BCA BBA.
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Encapsulation_ Review paper, used for researhc scholars
Per capita expenditure prediction using model stacking based on satellite ima...
Modernizing your data center with Dell and AMD
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding
A Presentation on Artificial Intelligence
MYSQL Presentation for SQL database connectivity

Codeception

  • 1. AUTOMATED TESTING WITH CODECEPTION PHP automated testing framework Jonathan Lau Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
  • 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 | jon@smokehousesoftware.com
  • 3. TEST STRATEGY What do we use these days? Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
  • 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 | jon@smokehousesoftware.com
  • 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 | jon@smokehousesoftware.com
  • 6. ACCEPTANCE TEST Let the robot do the clicking Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com
  • 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 | jon@smokehousesoftware.com
  • 8. 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
  • 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 | jon@smokehousesoftware.com
  • 10. 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
  • 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 | jon@smokehousesoftware.com
  • 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 | jon@smokehousesoftware.com
  • 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 | jon@smokehousesoftware.com
  • 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 | jon@smokehousesoftware.com
  • 15. KILL BUGS LIKE THE TERRAINS Good luck and thanks ! jon@smokehousesoftware.com ! Contributors: Kenneth Chiu Smokehouse Software | Jonathan Lau | jon@smokehousesoftware.com