Manual:PHP unit testing

Unit testing in MediaWiki is performed using the PHPUnit framework.

The unit tests are located in the tests. Tests are organized into a directory structure that matches the directory structure of the code that they are testing. For example: The unit tests for file includes/IP.php can be found in tests/phpunit/includes/IP.php.

Installing PHPUnit
To run the unit tests, PHPUnit must be installed. To install PHPUnit, follow the installation instructions in the PHPUnit manual.

Running the unit tests
Run the unit tests from the command line, ensuring that you are in the tests/phpunit directory.
 * On UNIX-like operating systems, run  . To see options for running the tests, run.
 * On Windows-family operating systems, run the   batch file.

Writing unit tests
The PHPUnit Manual provides good instructions for writing unit tests. Pay particularly close attention to the sections on writing and organizing tests.

Developers new to unit testing in MediaWiki should use SampleTest.php as a starting point – it contains helpful comments that will ease the process of learning to write unit tests.

Best practices
Developers should avoid inventing new conventions or borrowing conventions from other frameworks; using the already well-established PHPUnit conventions will serve to make MediaWiki's tests both useful and usable.