AUTOMATED TESTING WITH
CODECEPTION
PHP automated testing framework	

Jonathan Lau

Smokehouse Software | Jonathan Lau | jo...
MOTIVATION + BIO
•

Quick start guide for codeception	


•

Experience with running it in a Cake based project	


•

Intro...
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 ...
EFFORT VS RETURN
•

•

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

Functional / acceptance
tests c...
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 actio...
EXAMPLE CODE
<?php	

$I = new WebGuy($scenario);	

$I->amOnPage('/');	

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

$I->submitForm('#signup', ...
FUNCTIONAL TEST
•

Very similar concept as acceptance test	


•

No browser emulation 	


•

Emulate the actual web reques...
EXAMPLE CODE
<?php	

$I = new TestGuy($scenario);	

$I->amOnPage('/');	

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

$I->submitForm('#signup',...
UNIT TEST
•

Friendly only to developer	


•

Running the test subject in isolation and surrounding pieces are
stubbed out...
EXAMPLE CODE
<?php	

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

$I = new CodeGuy($scenario);	

$I->testMethod('U...
GENERAL PITFALLS
•

Javascript pop up box	


•

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


•

Delay tuning...
WHAT WORKS FOR US
•

Integration risk is always
larger than algorithmic
correctness	


•

Automating acceptance test
is a ...
KILL BUGS
LIKE THE
TERRAINS
Good luck and thanks	

!

jon@smokehousesoftware.com
!

Contributors: Kenneth Chiu	


Smokehou...
Upcoming SlideShare
Loading in …5
×

Codeception

1,339 views

Published on

A introduction on codeception

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,339
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
24
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Codeception

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

×