0
@magma_digital
RefactorGreen
Testing with Codeception
Jeremy Coates / @phpcodemonkey
Red
@magma_digital
Who am I?
๏ Jeremy Coates, CEO at Magma Digital Ltd
๏ Founder of PHPNW
๏ Lancashire Digital CIC founding di...
@magma_digital
What is Codeception?
A new powerful testing framework written in PHP, using Symfony2
Components, PHPUnit & ...
@magma_digital
Codeception:
๏ Is easy to read / write / debug
๏ Enables users with different roles to share common
test la...
@magma_digital
You can test your applications, through multiple approaches:
๏ Unit Tests
๏ Functional Tests
๏ Acceptance T...
@magma_digital
Codeception Features (1)
๏ Multiple backends, easily changed in configuration
- Selenium, PhpBrowser, Zombie...
@magma_digital
Codeception Features (2)
๏ Natively executes PHPUnit tests
๏ BDD-style scenario-driven tests
๏ WebServices ...
@magma_digital
Codeception Modules
Modules extend the connectivity and
therefore the things you can test with
Codeception ...
@magma_digital
Codeception utilises:
๏ Symfony2 Components
๏ PHPUnit
๏ Behat's Mink drivers
๏ Facebook webdriver
- for wir...
@magma_digital
๏ Browser emulation (Mink / Selenium / WebDriver)
๏ Test any website
๏ Test JavaScript & Ajax
๏ Readable by...
@magma_digital
Acceptance vs Functional vs Unit
๏ Emulate web request & submit to application
๏ Assert against response & ...
@magma_digital
Acceptance vs Functional vs Unit
๏ Runs on top of PHPUnit with bells & whistles
๏ Tests feel simpler / clea...
@magma_digital
Codeception: Howto?
๏ bootstrap - set up test folder & base files
๏ configure - to suit how you want to test
...
@magma_digital
Naysayers?
๏I don't need no stinking tests!
๏I already use PHPUnit, why
switch?
๏I Behat now, why write thi...
@magma_digital
Installation - Phar
๏Phar file installation is the preferred method
๏Grab Codeception phar executable:
- wge...
@magma_digital
Installation - Composer
๏ Install Composer as normal:
- curl -sS https://getcomposer.org/installer | php
๏A...
@magma_digital
Advanced Usage (1)
๏ Helpers - simply add Actions to your Guys
๏ Groups - put tests into groups and provide...
@magma_digital
Advanced Usage (2)
๏ PageObjects - new classes for defining UI maps
๏ StepObjects - common actions used in d...
@magma_digital
๏ Codeception 2.0 (June ’14):
- Removed Mink - replace with WebDriver module (Facebook API)
- Tests not exe...
@magma_digital
๏ Codeception 2.1 (April ’15):
- PSR-4 Support - test/_support - new location for all support code
- *Teste...
@magma_digital
Codeception: Add-ons
๏ http://codeception.com/addons - useful add-ons, not core
to Codeception
๏ WebCeption...
@magma_digital
Resources
๏ Codeception: http://codeception.com/
๏ Codeception Github: http://github.com/codeception/Codece...
@magma_digital
๏ Jeremy Coates, CEO at Magma Digital Ltd
๏ Founder of PHPNW
๏ Lancashire Digital CIC founding director
๏ @...
Upcoming SlideShare
Loading in...5
×

Testing with Codeception

13,236

Published on

Talk on Testing with Codeception presented at PHPNW April 2013, DPC 2013 Uncon, PFCongress 2013, PHPBNL 2014, DPC 2014, PHPNW 2014

Published in: Technology
1 Comment
22 Likes
Statistics
Notes
  • anybody using codeception for Magento?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
13,236
On Slideshare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
Downloads
100
Comments
1
Likes
22
Embeds 0
No embeds

No notes for slide

Transcript of "Testing with Codeception"

  1. 1. @magma_digital RefactorGreen Testing with Codeception Jeremy Coates / @phpcodemonkey Red
  2. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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
  16. 16. @magma_digital Installation - Composer ๏ Install Composer as normal: - curl -sS https://getcomposer.org/installer | php ๏Add Codeception to composer.json: - php composer.phar require “codeception/codeception:@stable” ๏Run Codeception from vendor path - vendor/bin/codecept bootstrap
  17. 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. 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. 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. 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. 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
  22. 22. @magma_digital Resources ๏ Codeception: http://codeception.com/ ๏ Codeception Github: http://github.com/codeception/Codeception/ ๏ Composer: http://getcomposer.org/ ๏ Selenium WebDriver: http://docs.seleniumhq.org/download/ ๏ ChromeDriver: http://code.google.com/p/chromedriver/ ๏ GhostDriver: https://github.com/detro/ghostdriver (now part of PhantomJS) ๏ PhantomJS: http://phantomjs.org/ ๏ Netbeans IDE: http://netbeans.org/downloads/ ๏ WebDriver Wire Protocol: - http://code.google.com/p/selenium/wiki/JsonWireProtocol
  23. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×