Chapter: Creating unit tests
|« Debugging and using jLog||^ Development helper tools|
See the definition of unit-test on wikipedia: https://en.wikipedia.org/wiki/Unit-testing .
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.
Creating tests with Simpletest ¶
This possibility has been removed from the source code of Jelix since Jelix 1.7. You can install the the simpletest-module package via Composer.