35

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.

aBhijit
  • 5,261
  • 10
  • 36
  • 56

3 Answers3

69

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.

Simon East
  • 55,742
  • 17
  • 139
  • 133
Alexandru Guzinschi
  • 5,675
  • 1
  • 29
  • 40
1

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

B4rb4ross4
  • 31
  • 1
  • 2
  • for me it didnt work, always only first test was run, but when i renamed file from Cept to Cest i realized later it is inevitable necessity it started to work for all methods not just first one what is confusing – FantomX1 Aug 08 '17 at 12:37
-1

Not that I'm a Codeception expert but this description may help - http://codeception.com/docs/07-AdvancedUsage.

Larry Borsato
  • 394
  • 3
  • 5