Manual:PHP unit testing/Writing unit tests for extensions

The recommended bootstrapping method for extensions is to use the UnitTestsList hook. By registering your tests with this hook you can use the mediaWiki core bootstrap support for things like autoloading classes, global functions etc. Unless your code is truly a standalone library, it's NOT recommended to include a few random MediaWiki core files with custom bootstrapping and attempt to make your tests stand alone.

To exclusively run your extensions tests, duplicate the suite.xml file in tests/phpunit/suite.xml to suite.extensions.xml only include the "extensions" testsuite as a child of testsuites. Then run the test with the command:

To test a single file you can pass the test file as a parameter to

Code
Let's assume our extension is named Fruits. In Fruits/Fruits.php main file add:

In AppleTest.php add:

To make easier to run test, you could create a Makefile something like this: