Chapter: Creating unit tests
|« Debugging and using jLog||^ Development helper tools|
− 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
Tests.phpas usual with PHPUnit)
php runtests.php --all-modulesto run tests in all modules
php runtests.php --module footo run tests only in the module foo
- you can add the option
--testtype xxxxand it launches only
*.xxxx.pu.phpfiles. That way, you can separate unit tests, functional tests etc..
You can use all others options of PHPUnit with runtests.php.