This page refers to VuFind 2.x; for notes on VuFind 1.x unit tests, see this page.
This page is aimed at developers who want to test that their changes have not broken existing VuFind functionality or who are interested in creating standard tests for new VuFind components. If you are interested in testing performance rather than functionality, see the Testing Performance page instead.
The test modules provided with VuFind use the PHPUnit testing framework. The framework can be installed using PEAR (see details on the project's homepage). Once installed, you will have a phpunit command line tool that you can use to run tests.
These tests were designed for use with VuFind's continuous integration system. As such, some tests create and destroy data. Although some safety mechanisms exist to reduce the chances of accidental data loss, THE TESTS SHOULD NEVER BE RUN ON A PRODUCTION SYSTEM.
The testing process was developed under Linux; this is the recommended platform for VuFind testing, and different procedures may need to be developed for other platforms like Windows.
The easiest way to run VuFind's tests is with the help of the Phing build tool. VuFind comes with a build.xml file that Phing can use to automate tasks.
1.) Install Phing
2.) Create a fresh copy of VuFind (i.e. git clone the repository to a fresh directory)
3.) Create a phing.sh script in the root of your fresh VuFind install to automatically pass important parameters to Phing (see build.xml for other parameters that may be set here with the -D parameter):
#!/bin/sh phing -Dmysqlrootpass=mypasswd $*
Follow these steps to run tests. Keep in mind that testing will create a test Solr index listening on port 8080. This may cause port conflicts if you test on a server that is already running applications on that port – plan accordingly.
1.) ./phing.sh startup
This command will start up an instance of VuFind containing test data that may be used by some of the tests.
2.) ./phing.sh phpunit
(the phpunit command will run tests and generate report data for use by continuous integration; phpunitfast will run tests more quickly by skipping reports)
3.) ./phing.sh shutdown
This command will turn off the VuFind test instance created by step 1.
VuFind unit tests (which check the functionality of individual components) can be found in the module/VuFind/tests/unit-tests directory of your VuFind installation.
VuFind integration tests (which check the interaction of components in a real running system) can be found in the module/VuFind/tests/integration-tests directory of your VuFind installation.
VuFind support modules (VuFindHttp, etc.) have their own tests directories, but these are configured to be run automatically as part of VuFind's main test suite.
The layout of the each test directory is designed to mirror the VuFind module's library (module/VuFind/src/VuFind). Tests should be placed in a directory that corresponds with the component being tested. For example, the unit tests for the \VuFind\Date\Converter class are found in “module/VuFind/tests/unit-tests/Date/ConverterTest.php”.
The VuFindTest namespace (code found in module/VuFind/src/VuFindTest) contains several classes which may be useful in writing new tests – a fake record driver in VuFindTest\RecordDriver and some base test classes containing convenience methods in VuFindTest\Unit.