Codeception is a popular testing framework for PHP. I have been using it for a number of my recent projects, both personal and professional, and would highly recommend it.
Please note, Codeception is not compatible with the Wikidot.com service. This article is written for web developers using PHP.
Functional testing works best when you have a large number of tests covering every possible scenario. The negative here, is that when you run those tests they can take a while.
Groups
This is where groups come in.
Codeception, which works very similarly to PHPUnit, allows you to group tests into logical sections so that you can run a smaller portion of your tests easily.
You might decide to group each test under a particular feature of your application (e.g. 'forum' or 'renamePages'), and then run that group of tests while you're making changes to the feature that they represent.
To define a group, include it in the PHPDoc above your testing function:
PHP
/**
* @group renamePages
*/
public function test_page_name_updated_after_rename()
{
// ...
}
Afterwards, simply use the --group modifier when running tests to only run those tagged with that particular group.
Codeception
$ codecept run --group renamePages
Stopping on first fail
Earlier today, I came across the need to run a large number of tests in a given group - and I knew with certainty that a large number of them would fail.
Generally it is accepted practice to fix the first error you come across, and then re-execute in case that first error was caused by the same issue as all subsequent errors. As a result, I wanted simplest possible output - and that meant showing only the first error.
I discovered today that there is a "fail fast" (or stop after first failure) feature in Codeception, which suited my needs perfectly.
How do you use it? Yet again, we simply pass an additional parameter when running tests.
Codeception
$ codecept run --group renamePages --fail-fast
Or, use the shorter alias:
Codeception
$ codecept run --group renamePages -f
Fortunately, if you're using PHPUnit there is similar functionality:
PHPUnit
$ phpunit --group renamePages --stop-on-failure
Have you used Codeception?
Let me know if you've found any neat tricks with Codeception (or PHPUnit) that you'd be willing to share. I'm only scratching the surface in this article - and it's a very powerful tool for PHP developers.
Post preview:
Close preview