Codeception - project news
I already wrote on Habré about Codeception - a framework for testing applications in PHP. If you've never written tests for your application before, you should definitely take a look at Codeception. It is very easy to use and made specifically to protect developers from routine.
Today I would like to tell you what features have appeared in the project recently, as well as answer a couple of popular questions.
Now for installation you no longer need PEAR. With him often there are many different problems requiring a tambourine and shamanistic songs. If you are a modern person and have forgotten all the ritual songs of ancient ancestors, try Composer. With it, you can easily install Codeception itself, as well as all the necessary libraries, including Mink and PHPUnit.
Instructions here .
Now you can write functional tests for the following frameworks: Symfony2, Zend Framework, symfony, Kohana, SocialEngine . The last two modules, by the way, were made by third-party developers, for which special thanks to them. Their example shows that it is not so difficult to make a module for your favorite framework.
Many say tests are the best documentation. But tests are not always written with the expectation of reading. In Codeception, everything is different, in Cest tests you describe your actions and the desired result.
If you use the phpDocumentor2 documentation generation system (formerly DocBlox), then using the plug-in built into Codeception this test will be added to the description of the method. It will be converted to text and take the following form:
With this method I can create group
If I execute \ Service \ Group :: create ("DemoGroup", 1)
I will see in repository "Model \ Group", {"name": “DemoGroup”, “user_id”: 1, “type”: “group”}
I will see result is “int”
Now in the documentation there will be information on how this or that method behaves depending on the parameters. How to connect the plugin - read here .
Codeception can now be connected to Continious Integration servers such as Jenkins and Bamboo. Unfortunately, integration testing has so far been possible only with Bamboo. But the result is written in XML and, in theory, should be easily picked up by other CI systems. If there will be problems with them - let us know, we will quickly correct everything.
All this, as well as many other goodies, is available in the latest version of Codeception 1.0.8 .
Install , use.
And now the answers to popular questions:
I’ll tell you a secret: Codeception is not a bike, but an add-on to PHPUnit. It allows you to perform script tests on the PHPUnit engine. At the same time, all your existing tests for PHPUnit Codeception will be able to catch without any problems. You can easily add functional and acceptance tests to them. A lot of tasks requiring crutches (for example, integration with Selenium, with a database) in Codeception have already been solved.
Codeception can run tests for Selenium. But tests in Codeception are easier to maintain; they are more flexible. For example, you can run some of the tests not in the browser, but through its Goutte emulator. Or do not use the web server for testing at all, but access the application directly. This will significantly reduce the execution time of your tests. In addition, Codeception takes care of all the problems associated with cleaning data between tests.
Question in style: why Linux, if there is Windows. Having alternatives is always good. At a minimum, a system that allows you to write acceptance tests in PHP will not be superfluous in the ecosystem.
In the near future, code coverage will be added and the number of supported frameworks will increase. But offer your ideas. What would you like to see in Codeception?
Today I would like to tell you what features have appeared in the project recently, as well as answer a couple of popular questions.
Installation through Composer
Now for installation you no longer need PEAR. With him often there are many different problems requiring a tambourine and shamanistic songs. If you are a modern person and have forgotten all the ritual songs of ancient ancestors, try Composer. With it, you can easily install Codeception itself, as well as all the necessary libraries, including Mink and PHPUnit.
Instructions here .
Framework support
Now you can write functional tests for the following frameworks: Symfony2, Zend Framework, symfony, Kohana, SocialEngine . The last two modules, by the way, were made by third-party developers, for which special thanks to them. Their example shows that it is not so difficult to make a module for your favorite framework.
Documentation Generation
Many say tests are the best documentation. But tests are not always written with the expectation of reading. In Codeception, everything is different, in Cest tests you describe your actions and the desired result.
$I->testMethod('\Service\Group::create');
$I->wantTo('create a group');
$I->executeTestedMethodWith('DemoGroup', 1)
->seeInRepository('Model\Group', array('name' => 'DemoGroup', 'user_id' => 1, 'type' => 'group'))
->seeResultIs('int');
If you use the phpDocumentor2 documentation generation system (formerly DocBlox), then using the plug-in built into Codeception this test will be added to the description of the method. It will be converted to text and take the following form:
With this method I can create group
If I execute \ Service \ Group :: create ("DemoGroup", 1)
I will see in repository "Model \ Group", {"name": “DemoGroup”, “user_id”: 1, “type”: “group”}
I will see result is “int”
Now in the documentation there will be information on how this or that method behaves depending on the parameters. How to connect the plugin - read here .
Basic support for CI systems
Codeception can now be connected to Continious Integration servers such as Jenkins and Bamboo. Unfortunately, integration testing has so far been possible only with Bamboo. But the result is written in XML and, in theory, should be easily picked up by other CI systems. If there will be problems with them - let us know, we will quickly correct everything.
All this, as well as many other goodies, is available in the latest version of Codeception 1.0.8 .
Install , use.
And now the answers to popular questions:
Why Codeception if there is PHPUnit?
I’ll tell you a secret: Codeception is not a bike, but an add-on to PHPUnit. It allows you to perform script tests on the PHPUnit engine. At the same time, all your existing tests for PHPUnit Codeception will be able to catch without any problems. You can easily add functional and acceptance tests to them. A lot of tasks requiring crutches (for example, integration with Selenium, with a database) in Codeception have already been solved.
Why Codeception if there is Selenium?
Codeception can run tests for Selenium. But tests in Codeception are easier to maintain; they are more flexible. For example, you can run some of the tests not in the browser, but through its Goutte emulator. Or do not use the web server for testing at all, but access the application directly. This will significantly reduce the execution time of your tests. In addition, Codeception takes care of all the problems associated with cleaning data between tests.
Why Codeception if there is a Behat?
Question in style: why Linux, if there is Windows. Having alternatives is always good. At a minimum, a system that allows you to write acceptance tests in PHP will not be superfluous in the ecosystem.
Future plans
In the near future, code coverage will be added and the number of supported frameworks will increase. But offer your ideas. What would you like to see in Codeception?