Pages

How to create PHPUnit Test Case in Codeception?

In this article we are going to see very simple command to generate PHPUnit test case in CodeCeption.

As we know, codeception build on PHP Unit, so it support all type of PHP Unit test case. That means, the test case will contain setup and teardown method for test initialization and closure functions.

And, as it is a PHP Unit format, so there will not be any Guy initialization. Just raw PHP Unit format test steps can be executed. Yes, we can use Guy Class, but should not be included as we have different format for those Guy class based test cases.

Beside, those Guy Class based test cases needs two time compilation, but PHP Unti test case need only single time compilation.

Like as other format, PHPUnit type test case In needs to use Test as post fix of a test case which is understood by codeception. That means, if our test case name is SugnUp, so if we are writing PHPUnit type test case, then it will be named as SignUpTest.php.

What is PHP Unit Format :
Like as other unit test case, PHP Unit will also have setup/tear down. Here is sample PHP Unit test case structure :

1: <?php

2: class SignUpTest extends \PHPUnit_Framework_TestCase

3: {

4: protected function setUp()

5: {

6: // Initialization methods

7: }

8: protected function tearDown()

9: {

10: //Closure activities/ methods

11: }

12: // tests

13: public function testMe()

14: {

15: }

16: }

So, now lets see the command. When we need to generate a PHP format format test case: