Quick links: Content - sections - sub sections
EN FR

Table of content

Unit tests should always be used in any project. Jelix allows to integrate easily tests in modules.

Creating tests with PHPUnit

Using PHPUnit to create tests is the prefered method. See the manual of PHPUnit to know how to use it. You must install PHPUnit, it is not provided in the Jelix package.

Jelix brings some helpers. The create-jelix-app command has created a tests/runtests.php in your application (or copy the file lib/jelix-scripts/templates/tests/runtests.php). You will launch this file instead of PHPUnit. It then discover your tests files in all modules. It avoids to not fill a phpunit.xml with all your tests stored in your modules.

To do so:

  • create your tests in the tests/ directory of your modules
  • store them in files with the suffix .pu.php (and not Tests.php as usual with PHPUnit)
  • launch php runtests.php --all-modules to run tests in all modules
  • launch php runtests.php --module foo to run tests only in the module foo
  • you can add the option --testtype xxxx and it launches only *.xxxx.pu.php files. That way, you can separate unit tests, functional tests etc..

You can use all others options of PHPUnit with runtests.php.