Codeception BDD style Unit tests
Nov 21, 2013, 8:09:25 PMRecently davertMik had announced an addition to Codeception framework that allows BDD style unit test. Pretty nice like this
$this->specify('post can be published', function() {
$this->post->setTitle('Testing is Fun!');
$this->post->setBody('Thats for sure');
expect_that($this->post->publish());
});
Two new additional libraries introduced for this Specify and Verify
These libs are very easy to add into you project via Composer.
Specify
is a helper trait that allow to organize tests in "containers" for better readability like
$this->specify("i can change my name", function() {
$this->user->name = 'jon';
$this->assertEquals('jon', $this->user->name);
});
very interesing is DataProvider feature that will help to test a number of edge conditions
$this->specify("should calculate square numbers", function($number, $square) {
$this->assertEquals($square, $number*$number);
}, ['examples' => [
[2,4],
[3,9]
]]);
Verify
add 2 functions verify() and alias expect() and wrap all PHPUnit assertions in such way
verify($rate)->greaterThan(5);
verify($rate)->lessThen(10);
verify($rate)->lessOrEquals(8);
verify($rate)->greaterOrEquals(7);
verify($user->isAdmin())->true();
verify($user->invitedBy)->null();
verify($user->getComments())->isEmpty();
What is missing ?
As for me these libs are exactly what I wanted from Codeception. The only thing I still need is ability to generate steps report on passed test. As now I describe everything in human-readable format via Specify - I would like to be able to get "passed-tests-walk-through" as a report.