Codeception BDD style Unit tests > stdout.in Ievgen Kuzminov IT blog

Codeception BDD style Unit tests

Nov 21, 2013, 8:09:25 PM

Recently 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]
]]);

see detailed docs

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();

see detailed docs

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.

comments powered by Disqus
Ievgen
Kuzminov "iJackUA"
Web Team Lead
at MobiDev (Kharkiv, Ukraine)
Code in Ruby and Elixir, but still love PHP. Explore ES6 and Vue.js. Explore databases, use Ubuntu and MacOS, think about IT people and management

Notes


In Google Chrome you can open Dev Tools for Dev Tools. Open it in separate window and then Ctrl + Shift + J.



Redis 2.8.0 released! At the first look has couple of very promising things to play aroud with

  • new *SCAN commands for pattern filering (like scan 0 MATCH key:1*)
  • Pub/Sub notification on expire and data manipulation events - that brings some ideas of pseudo data consistency implementation