Unit Test runs the unit tests that modules include, and can show which lines of code the tests ran (code coverage). It's for developers working on module code.
ACP > Modules > Developer > Unit Test
On the Run Unit Tests tab:
| Option | What it does |
|---|---|
| Test to Run | One test file, or all of them |
| Suppress Activity Log | Keeps Activity Log entries made during the tests out of the log |
| Coverage Analysis | Records which lines the tests ran. Needs the Xdebug PHP extension. |
| Enable Code Profiler | Writes Xdebug profiler files. Needs Xdebug. |
The results appear as the tests run. Coverage Browser shows each file, with the lines the tests ran and missed.
Some tests create and delete data. Run them on a development site, not a live one.
Tests live in a module's tests/ folder. Each file, such as tests/string.php, defines a function named test_<Module>_<file>():
function test_myModule_string()
{
jrUnitTest_init_test('format a price');
if (myModule_format_price(5) !== '5.00') {
jrUnitTest_exit_with_error('expected 5.00');
}
}
jrUnitTest_init_test() starts each test, and jrUnitTest_exit_with_error() fails it. To attribute coverage to a file, call jrUnitTest_add_coverage_file(). The folder needs the same .htaccess file as other modules' tests/ folders.