Date post: | 10-May-2015 |
Category: |
Technology |
Upload: | jonathan-lau |
View: | 607 times |
Download: | 6 times |
Smokehouse Software | Jonathan Lau | [email protected]
AUTOMATED TESTING WITH CODECEPTION
PHP automated testing framework Jonathan Lau
Smokehouse Software | Jonathan Lau | [email protected]
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]
WAYS TO TEST• Unit test
• White box testing
• Full knowledge of the code base
• Run script during build / check out
!
• Functional test
• Knowledge of input and expected output
• No browser emulation
• Acceptance test
• Yes, still need this for sanity sake
Smokehouse Software | Jonathan Lau | [email protected]
Coverage
Maintenance effort
Unit test
Functional test
Acceptance test
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
Smokehouse Software | Jonathan Lau | [email protected]
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]
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]
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]
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]
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]
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]
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]
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]
KILL BUGS LIKE THE
TERRAINSGood luck and thanks
!Contributors: Kenneth Chiu