RETURN ZERO
RETURN ZERO

Reputation: 25

Unit test inside a Module in yii2

How can i perform unit test inside a module. here's my project structure enter image description here

Upvotes: 0

Views: 427

Answers (1)

Naktibalda
Naktibalda

Reputation: 14102

yii2-app-advanced is a good example of solution.

Add include section to project level codeception.yml file:

include:
    - modules/api
    - modules/dtr

Include setting is documented at https://codeception.com/docs/08-Customization#One-Runner-for-Multiple-Applications

You need codeception.yml file in modules/dtr directory, it lools like normal standalone codeception.yaml file.

  • codecept run command would run project level tests and tests of included modules.
  • codecept run modules/dtr/tests/unit/ executes all unit tests of that module.
  • codecept run modules/dtr/tests/unit/models/FirstTest.php executes specific test

If you don't want to have a top level codeception.yml file, you can specify path to module directory (you need codeception.yml file there anyway).

  • codecept run -c modules/dtr executes all tests
  • codecept run -c modules/dtr tests/unit/models/FirstTest.php executes specific test
  • but it is more convenient to use name filter - codecept run -c modules/dtr :FirstTest

-c parameter is documented at https://codeception.com/docs/07-AdvancedUsage#Running-from-different-folders

Upvotes: 2

Related Questions