Sugan Sugan - 2 years ago 330
PHP Question

How to run unit tests (codeception) in Yii2 framework?

I am new to Codeception concept and trying to run the unit test scripts in this directory:


DB configuration for testing has been done in config-local.php.

Now my question is how to run the scripts, I have tried the below code in terminal:

frontend tests
cd frontend
codecept build
codecept run

It says Codecept: command not found.

Can any one help me out?

Answer Source

Install Codeception via composer:

$ composer require "codeception/codeception"

From now on Codeception (with installed PHPUnit) can be run as:

$ php vendor/bin/codecept

Next, initialize your testing environment:

$ php vendor/bin/codecept bootstrap

Now, go to the Yii2 'tests/codeception/frontend' folder and run:

$ php vendor/bin/codecept build
$ php vendor/bin/codecept run

You can read more about Codeception installation steps from this link.

Also, if you want codecept command to work from the command line:

codecept bootstrap
codecept run

... then you need to configure the $PATH variable properly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download