2. @magma_digital
Who am I?
๏ Jeremy Coates, CEO at Magma Digital Ltd
๏ Founder of PHPNW
๏ Lancashire Digital CIC founding director
๏ @phpcodemonkey
๏ linkedin.com/in/jeremycoates
3. @magma_digital
What is Codeception?
A new powerful testing framework written in PHP, using Symfony2
Components, PHPUnit & Behat's Mink drivers (for wire protocol).
In the words of Codeception:
Codeception is a BDD-styled PHP testing
framework, whose only requirements are
basic knowledge of PHP and the theory of
automated testing. Codeception is kept as
simple as possible for any kind of users.
“
4. @magma_digital
Codeception:
๏ Is easy to read / write / debug
๏ Enables users with different roles to share common
test language
๏ Integrates with
IDE code completion
๏ Describes actions from
a users point of view
๏ Makes testing fun!
The Pitch
5. @magma_digital
You can test your applications, through multiple approaches:
๏ Unit Tests
๏ Functional Tests
๏ Acceptance Tests
๏ API Tests
๏ Database Repopulation
Focus on Acceptance / Functional / Db
What Does Codeception Do?
5 of 46
6. @magma_digital
Codeception Features (1)
๏ Multiple backends, easily changed in configuration
- Selenium, PhpBrowser, ZombieJS, PhantomJS*
๏ Elements matched by Name, CSS, XPath
๏ Data Cleanup after each run
๏ Integrate with
- Symfony2, Zend Framework, Kohana, Yii, Laravel etc.
๏ Continuous Integration systems like Jenkins or Bamboo
7. @magma_digital
Codeception Features (2)
๏ Natively executes PHPUnit tests
๏ BDD-style scenario-driven tests
๏ WebServices testing via REST,
SOAP, XML-RPC
๏ Generates HTML, XML, TAP, JSON reports
๏ Simple Fixtures (known test data)
๏ Database and Doctrine ORM helpers
๏ CodeCoverage and Remote CodeCoverage
8. @magma_digital
Codeception Modules
Modules extend the connectivity and
therefore the things you can test with
Codeception - additional methods for
the $I object.
This is the current released set of
modules, however new ones are
being created with regularity e.g.
ZF2 has recently been accepted
as a module.
9. @magma_digital
Codeception utilises:
๏ Symfony2 Components
๏ PHPUnit
๏ Behat's Mink drivers
๏ Facebook webdriver
- for wire protocol
License:
๏ MIT Licence
What You Need to Know?
Requires:
๏ PHP 5.3+ (v1.x)
๏ CURL enabled
Developed by:
๏ Michael Bodnarchuk @davert,
based in Kiev, Ukraine runs
outsourcing company Codegyre
๏ Sponsored by 2amigOS! Since
June 2013 (sponsors of Yii)
10. @magma_digital
๏ Browser emulation (Mink / Selenium / WebDriver)
๏ Test any website
๏ Test JavaScript & Ajax
๏ Readable by humans (managers!)
๏ Stability against code changes
๏ Some false positives
๏ SLOW!
Acceptance vs Functional vs Unit
11. @magma_digital
Acceptance vs Functional vs Unit
๏ Emulate web request & submit to application
๏ Assert against response & query internal values
๏ Framework based
๏ Still readable by humans
๏ Can't test JS/Ajax
๏ Risk of false positives
๏ Less slow
12. @magma_digital
Acceptance vs Functional vs Unit
๏ Runs on top of PHPUnit with bells & whistles
๏ Tests feel simpler / cleaner
๏ Not readable by humans
๏ Test application core
๏ Isolated units
๏ Fastest
13. @magma_digital
Codeception: Howto?
๏ bootstrap - set up test folder & base files
๏ configure - to suit how you want to test
๏ build - when add suite, automatic otherwise
๏ generate:cept generate:test generate:phpunit
generate:scenarios <suite> <test>
๏ Write test - unfortunately you still have to do
this bit!
๏ run --steps --debug --silent --report --coverage
--html --xml --json [<suite>] [<test>]
14. @magma_digital
Naysayers?
๏I don't need no stinking tests!
๏I already use PHPUnit, why
switch?
๏I Behat now, why write things
only once?
๏I already use Selenium (with
PHPUnit), why change?
๏What's all this Guy business
about?
Don’t need it,
not listening !
15. @magma_digital
Installation - Phar
๏Phar file installation is the preferred method
๏Grab Codeception phar executable:
- wget http://codeception.com/codecept.phar -O codecept.phar
๏Prepare tests directory and configs:
- php codecept.phar bootstrap
17. @magma_digital
Advanced Usage (1)
๏ Helpers - simply add Actions to your Guys
๏ Groups - put tests into groups and provide hooks for them
- $scenario->group(<groupname>) $scenario-
>group(array(<groupname>, <groupname>))
- run --group <groupname> (or -g)
๏ Console - interactive console, try commands without tests
๏ Config Reconfigure - dynamically change module config (from helpers
->_reconfigure(array(‘browser’ => ‘chrome’)); )
๏ Stubs - mocking code Stub::makeEmpty (see also AspectMock
framework)
18. @magma_digital
Advanced Usage (2)
๏ PageObjects - new classes for defining UI maps
๏ StepObjects - common actions used in different tests
๏ Events - fire at various points during test execution
๏ Extension & Group classes that can hook into events and produce
their own. Extend anything
๏ Conditional Asserts - don’t stop a test if assert fails
- each ‘see’ method has ‘canSee’ equivalent
- each ‘dontSee’ method has ‘cantSee’ equivalent
๏ Comments - $I[‘describe everything in comments and then automate’];
19. @magma_digital
๏ Codeception 2.0 (June ’14):
- Removed Mink - replace with WebDriver module (Facebook API)
- Tests not executed twice as previous
- PHP 5.4+
- No Guys, new folder structure _log -> _output, _helpers -> _support
- Remove: Selenium/2, ZombieJS -> WebDriver (Facebook API)
- Updated dependencies - e.g. Guzzle 4
- No BC breaks? :)
Roadmap(Achieved)
20. @magma_digital
๏ Codeception 2.1 (April ’15):
- PSR-4 Support - test/_support - new location for all support code
- *Tester classes generated once - traits for common code, customise :)
- Dependency Injection - page/step objects, modules -> helpers
- Simplified config - specify helpers in config
- Environment Matrix - tests/_envs folder. codecept run —env dev,chrome
- Module Parts - pic’n’mix partial loading of actions
- WebDriver - session snapshots - skip logging in every time!
- No major BC breaks? :)
Roadmap(Next)
21. @magma_digital
Codeception: Add-ons
๏ http://codeception.com/addons - useful add-ons, not core
to Codeception
๏ WebCeption (Application): web front end for Codeception
๏ VisualCeption (Module): visual regression tests
๏ DrushDb (Extension): populate/clean up Drupal site with
drush / sql-sync during test runs
๏ RemoteDebug (Extension): code coverage from remote
sites
23. @magma_digital
๏ Jeremy Coates, CEO at Magma Digital Ltd
๏ Founder of PHPNW
๏ Lancashire Digital CIC founding director
๏ @phpcodemonkey
๏ linkedin.com/in/jeremycoates
Now Get Testing...
DownloadSlides Here!
http://bit.ly/test_with_codeception