Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeception - What is the difference between cest and cept?

I just started using TDD approach and came across codeception.

I searched the web a lot but didn't find a proper explanation or differentiation between cest and cept files in codeception.

like image 425
aBhijit Avatar asked Dec 04 '14 14:12

aBhijit


People also ask

What is Cest Codeception?

Cest is a common test format for Codeception, it is “Test” with the first C letter in it. It is scenario-driven format so all tests written in it are executed step by step. Unless you need direct access to application code inside a test, Cest format is recommended.

How do you skip tests in Codeception?

So to make your scenario skipped during test run : You must have $scenario as second input param in your test. make call : $scenario->skip();

What is Codeception PHP?

Codeception is a framework used for creating tests, including unit tests, functional tests, and acceptance tests. Despite the fact that it is based on PHP, the user needs only basic knowledge for starting work with the framework, thanks to the set of custom commands offered by Codeception.


2 Answers

Their format is the only difference.

Cept is a scenario-based format and Cest is a class based format.

Cept example:

<?php    
$I = new AcceptanceTester($scenario);
$I->wantTo('log in as regular user');
$I->amOnPage('/login');
$I->fillField('Username','john');
$I->fillField('Password','secret');
$I->click('Login');
$I->see('Hello john');

Cest example:

<?php
class UserCest
{
    public function loginAsRegularUser(\AcceptanceTester $I) 
    {
        $I->wantTo('log in as regular user');
        $I->amOnPage('/login');
        $I->fillField('Username','john');
        $I->fillField('Password','secret');
        $I->click('Login');
        $I->see('Hello john');            
    }
}

Non-developers may find the Cept format more friendly and approachable. PHP developers may prefer the Cest format which is able to support multiple tests per file and easy reuse of code by adding additional private functions.

In the end it is just a matter of taste and you can choose the format you prefer.

like image 173
Alexandru Guzinschi Avatar answered Oct 11 '22 05:10

Alexandru Guzinschi


If you have a Cest with 2 test methods like

<?php
class UserCest
{
    public function test1(\AcceptanceTester $I) 
    {
        $I->see('Hello john');            
    }

    public function test2(\AcceptanceTester $I) 
    {
        $I->see('Hello jeff');            
    }
}

That is thew Equivalent to test1Cept.php:

<?php
$I = new AcceptanceTester($scenario);
$I->see('Hello john');

test2Cept.php:

<?php
$I = new AcceptanceTester($scenario);
$I->see('Hello jeff');

It's just 2 different ways of structuring you test code

like image 1
B4rb4ross4 Avatar answered Oct 11 '22 03:10

B4rb4ross4