Codeception is PHP framework for testing web applications in BDD-style. It was started about a year ago, as a plugin for symfony1, to speed up and simplify functional testing inside the framework. But as time passed, Codeception evolved to standalone project, with support of various frameworks and engines. It's built on top of wonderful PHPUnit, but with aim for acceptance, and functional scenario driven tests. In this post we will remind why you may like Codeception and why we feel it's awesome.
Yes, the first reason is PHP. If you are PHP developer it's natural you would like to write tests in PHP. Codeception provides you the best way to do so. Any IDE with code completion and syntax highlighting will help you write tests faster and without stupid syntax mistakes. Usage of PHP inside of tests unleashes the true power and control over the test flow. You can use your application classes or create testing helpers. Also you can get values (with grabbers) from results and use them in your tests. You just control everything. And yep, use everything you like from PHPUnit.
<?php $I = new TestGuy($scenario); $I->wantTo('launch missiles from my website'); $I->amOnPage('/launch'); $I->click('Launch Missiles!') $I->see('Missiles launched'); ?>
You know, KISS is our first principle. Even Codeception requires basic knowledge of PHP it narrows testing to using PHP DSL where all actions are defined with user's perspective. Just enter the
$I-> and select action from a list and put parameters. That's how a test is written. Also add minimal configuration in YAML format, and installation by downloading a single phar archive. It's really that simple.
You decided to migrate your application from symfony1 to Symfony2, from Kohana to Zend? You decided to test with Selenium inside a real browser? Your tests will run inside chosen the engine, no matters what happen. Codeception using one common syntax for all the backends. Frameworks support allows you to create more complex assertion and check the internals of your application, not only the visible part.
Here comes a QA and says: I need XPath, I need complex selectors, I need to test UI elements strictly. No problems! You can use CSS selectors, XPath locators and even combine them with
Locator class. You can also test your SOAP and REST webservices, pragmatical use XMLs (defined in jQuery-like style) and JSONs (as PHP arrays). Despite Codeception tend to be simple, it can be used by QAs creating solid tests automation platform.
<?php $I->click('New User'); $I->click('#user_1 .user_new'); $I->click('//*[@id = 'user_1']/descendant::a'); $I->see('Title', Locator::combine('h1','h2','h3')); $I->fillField(Locator::tabIndex(1), 'davert'); $I->see('Log In', Locator::href('/login.php')); ?>
Tests isolation is a problem. Most of testing frameworks puts it's solving to your shoulders. But Codeception tries to fetch your needs and provide Data cleanup from the box. With the
Db module you can repopulate database (MySQL, PostgreSQL, ...), after each run, use SQLite (for faster testing), or just run all tests inside transaction (in functional or unit testing). Also Codeception have modules for using and cleaning Memcache and AMQP storages.
And just to mention, the results of tests are readable to non-technical guys. When you export result in HTML you will see the cool colored page with all passed steps described in pure English. Also test results are readable to robots: export result as XML and the CI-server (Jenkins, Bamboo) will use them.
If you are still deciding weather or not to test your application, start doing it now. And Codeception is the right tool for this.