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


Linkify - jQuery plugin for finding URLs in plain-text and converting them to HTML links. It works with all valid URLs and email addresses



Remodal - flat, responsive, lightweight, fast, easy customizable modal window jquery plugin with declarative state notation and hash tracking



Giving a try to Ubuntu 14.04 - so far it's ok. More stable and refined. But it seem to have problems with Cinnamon 2 installation. Oh fine... will wait for Linux MInt 17 to use on my Work machine



Updated blog. Mostly "under-the-hood" changes according to latest Yii2 state, some CSS and server optimisations. In case of any issues please feel free to comment here