+ All Categories
Home > Technology > Codeception

Codeception

Date post: 10-May-2015
Category:
Upload: jonathan-lau
View: 607 times
Download: 6 times
Share this document with a friend
Description:
A introduction on codeception
Popular Tags:
15
Smokehouse Software | Jonathan Lau | [email protected] AUTOMATED TESTING WITH CODECEPTION PHP automated testing framework Jonathan Lau
Transcript
Page 1: Codeception

Smokehouse Software | Jonathan Lau | [email protected]

AUTOMATED TESTING WITH CODECEPTION

PHP automated testing framework Jonathan Lau

Page 2: Codeception

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

Page 3: Codeception

Smokehouse Software | Jonathan Lau | [email protected]

TEST STRATEGYWhat do we use these days?

Page 4: Codeception

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

Page 5: Codeception

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

Page 6: Codeception

Smokehouse Software | Jonathan Lau | [email protected]

ACCEPTANCE TESTLet the robot do the clicking

Page 7: Codeception

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

Page 8: Codeception

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!');

?>

Page 9: Codeception

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

Page 10: Codeception

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]'));

?>

Page 11: Codeception

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

Page 12: Codeception

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'));

?>

Page 13: Codeception

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

Page 14: Codeception

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…

Page 15: Codeception

Smokehouse Software | Jonathan Lau | [email protected]

KILL BUGS LIKE THE

TERRAINSGood luck and thanks

[email protected]

!Contributors: Kenneth Chiu


Recommended