SlideShare uma empresa Scribd logo
1 de 15
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Applitools
 

Mais procurados (20)

CI / CD w/ Codeception
CI / CD w/ CodeceptionCI / CD w/ Codeception
CI / CD w/ Codeception
 
Test automation with php codeception
Test automation with php codeceptionTest automation with php codeception
Test automation with php codeception
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
 
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)
 
Testing PHP with Codeception
Testing PHP with CodeceptionTesting PHP with Codeception
Testing PHP with Codeception
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Integration Testing in Python
Integration Testing in PythonIntegration Testing in Python
Integration Testing in Python
 
Automation Frame works Instruction Sheet
Automation Frame works Instruction SheetAutomation Frame works Instruction Sheet
Automation Frame works Instruction Sheet
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravel
 
Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)
 
Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)
 
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
Selenium Basics Tutorial
Selenium Basics TutorialSelenium Basics Tutorial
Selenium Basics Tutorial
 
Integration testing - A&BP CC
Integration testing - A&BP CCIntegration testing - A&BP CC
Integration testing - A&BP CC
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 

Semelhante a Codeception

The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2
Rosie Sherry
 

Semelhante a Codeception (20)

Automated Acceptance Test Practices and Pitfalls
Automated Acceptance Test Practices and PitfallsAutomated Acceptance Test Practices and Pitfalls
Automated Acceptance Test Practices and Pitfalls
 
Test automation lesson
Test automation lessonTest automation lesson
Test automation lesson
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016
 
Continuous Integration, Deploy, Test From Beginning To End 2014
Continuous Integration, Deploy, Test From Beginning To End 2014Continuous Integration, Deploy, Test From Beginning To End 2014
Continuous Integration, Deploy, Test From Beginning To End 2014
 
STARWest: Use Jenkins For Continuous 
Load Testing And Mobile Test Automation
STARWest: Use Jenkins For Continuous 
Load Testing And Mobile Test AutomationSTARWest: Use Jenkins For Continuous 
Load Testing And Mobile Test Automation
STARWest: Use Jenkins For Continuous 
Load Testing And Mobile Test Automation
 
Use Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test AutomationUse Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test Automation
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
 
Test Automation Pyramid
Test Automation PyramidTest Automation Pyramid
Test Automation Pyramid
 
QAorHighway2016
QAorHighway2016QAorHighway2016
QAorHighway2016
 
Lightning Talks by Globant - Automation (This app runs by itself )
Lightning Talks by Globant -  Automation (This app runs by itself ) Lightning Talks by Globant -  Automation (This app runs by itself )
Lightning Talks by Globant - Automation (This app runs by itself )
 
6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation Architecture6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation Architecture
 
Are Your Continuous Tests Too Fragile for Agile?
Are Your Continuous Tests Too Fragile for Agile?Are Your Continuous Tests Too Fragile for Agile?
Are Your Continuous Tests Too Fragile for Agile?
 
Automated Acceptance Tests in .NET
Automated Acceptance Tests in .NETAutomated Acceptance Tests in .NET
Automated Acceptance Tests in .NET
 
How EVERFI Moved from No Automation to Continuous Test Generation in 9 Months
How EVERFI Moved from No Automation to Continuous Test Generation in 9 MonthsHow EVERFI Moved from No Automation to Continuous Test Generation in 9 Months
How EVERFI Moved from No Automation to Continuous Test Generation in 9 Months
 
Continuous Delivery Testing @HiQ
Continuous Delivery Testing @HiQContinuous Delivery Testing @HiQ
Continuous Delivery Testing @HiQ
 
The Testing Planet Issue 2
The Testing Planet Issue 2The Testing Planet Issue 2
The Testing Planet Issue 2
 
Course Slides.pdf
Course Slides.pdfCourse Slides.pdf
Course Slides.pdf
 
Automated Testing Using Selenium
Automated Testing Using SeleniumAutomated Testing Using Selenium
Automated Testing Using Selenium
 
Definition of Done and Product Backlog refinement
Definition of Done and Product Backlog refinementDefinition of Done and Product Backlog refinement
Definition of Done and Product Backlog refinement
 
Enterprise Workflows When You Aren't Enterprise
Enterprise Workflows When You Aren't EnterpriseEnterprise Workflows When You Aren't Enterprise
Enterprise Workflows When You Aren't Enterprise
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

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