Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Codeception

 Codeception

A brief introduction to Codeception testing framework

Michael Bodnarchuk

August 05, 2012
Tweet

More Decks by Michael Bodnarchuk

Other Decks in Programming

Transcript

  1. Why Codeception? • The simplest PHP testing tool ever. •

    Multiple frameworks integrations. • Powered by PHPUnit
  2. Judge by code $I = new WebGuy($scenario) $I->wantTo(‘sign up as

    a customer’); $I->click(‘Sign Up’); $I->fillField(‘name’,’Michael’); $I->fillField(‘password’,’qwerty’); $I->click(‘Submit’); $I->see(‘Hello, Michael!’);
  3. HOW IS THAT EASY TO WRITE? It’s just a PHP

    code. Yep, it’s pretty clean, but…
  4. Execute test Codeception PHP Testing Framework v1.1.0 Powered by PHPUnit

    3.6.10 by Sebastian Bergmann. Suite acceptance started Trying to sign in as a customer (RegisterCept.php) Scenario: * I click “Sign Up" * I fill field “name",“Michael" * I fill field “password",“qwerty" * I click “Submit" * I see “Hello, Michael" OK Time: 2 seconds, Memory: 10.25Mb OK (1 test, 1 assertion) $ php codecept.phar run
  5. Get more information Codeception PHP Testing Framework v1.1.0 Powered by

    PHPUnit 3.6.10 by Sebastian Bergmann. Suite acceptance started Trying to sign in as a customer (RegisterCept.php) Scenario: * I click “Sign Up" => Moved to page http://localhost/signup * I fill field “name",“Michael" * I fill field “password",“qwerty" * I click “Submit" => Moved to page http://localhost/user/michael * I see “Hello, Michael" OK Time: 2 seconds, Memory: 10.25Mb OK (1 test, 1 assertion) $ php codecept.phar run --debug
  6. Even more? Debug! • Each broken step is highlighted. •

    The last response is saved when test fails. • Logs are written. • Page screenshots can be captured.
  7. A bit of theory • We describe actions from user’s

    perspective. • We surf the site by clicking links, filling forms. • We expect to see predictable results on page.
  8. It’s up to you how to run the test •

    In a command line with PHPBrowser • Inside a real browser with Selenium • As a functional test of MVC framework
  9. Installation 1. Download ‘codecept.phar’ 2. Save it to PHP project.

    3. Execute: php codecept.phar bootstrap php codecept.phar build