What is Cest Test Case format in Codeception? How to create Cest Test Case?

In this article we are going to see How can we create Cest test case in codeception?

As we know , codeception has 3 type of tests, we have to define what type of test we are going to build.

What is Cest format ?
This actually traditional PHPUnit/Junit format. It is better for developer or unit testers to read. Even, personally I like this type of test case as I am habituated in writing Unit Tests cases. We can group test steps, having a private function as common test steps. This is helpful when you have long test steps.

When we need to create PHPUnit type test case In codeception, we need to use Cest as post fix of a test which is understand by codeception command. That means, if our test case name is SugnUp, so if we are writing BDD type test case, then it will be named as SignUpCest.php.

Cest Format :
This type of test cases takes the Guy ( either WebGuy/ TestGuy/ TestGuy) class as parameter inside of a test method.

Like :
   1:  <?php
   2:  use \WebGuy; 
   3:  class SignUpCest
   4:  {
   5:      public function _before()
   6:      {
   7:          //similar to setup/initial of phpunit or Junit 
   8:      }
   9:      public function _after()
  10:      {
  11:          //similar to teardown/closure of phpunit/junit 
  12:      }
  13:      // tests
  14:      public function tryToTest(WebGuy $I) {
  15:          $I->wantTo("Test Registration Page");
  16:          $I->amOnPage('/');
  17:      }
  18:  } 



So, now lets move on to command. When we need to generate a Cest format Acceptance test case(acceptance is a type of test suit) :
php codecept.phar generate:cest <suitename> <testname>

[if you use composer, then : <path to codecept>/codecept generate:cest <suitename> <testname> ]

For example, if we want to generate an Acceptance test case named as SignUp in cest format , then

php codecept.phar generate:cest acceptance SignUp


image


We can see a file generated SignUpCest.php in the tests/acceptance/ folder and it will follow the configuration of acceptance.suite.yml
So, we can generate cest format test case and we can ready to write codes.

Note : It is more of developer friendly test case format, some time feels complex in reading but it eliminates repetitive test steps.

Thanks…:)







No comments:

Post a Comment