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.

Register your tests with UnitTestsList
Let's assume our extension is named Fruits.
 * 1) Create a hook function for onUnitTestsList.
 * 2) Register the hook with UnitTestsList.

Create your tests
Let's say our Fruits extension has a class called.
 * 1) Create a test file in your extension’s tests/phpunit/ directory, named
 * 2) * Make sure that the file name ends in  or else phpunit will not be able to discover it.
 * 3) Create a class in that file named   and extend the MediaWikiTestCase class.
 * 4) The class must contain a   that calls   as its first task.
 * 5) The class should contain a   that calls   as its last task.
 * 6) Each of your test functions should :
 * 7) * be.
 * 8) * begin their function name with.
 * 9) It’s a good idea to add an   comment to the class. This group name can then be referred to later in order to run tests only in this group or exclude them. You can also place an @group comment above each test function if you wish to further isolate your tests.

Create a custom test suite
runs with a default test suite defined in. You can alter that test suite by doing the following:  Copy the  file to   Edit the suite.extensions.xml file. Save the file. Run the tests with the custom suite configuration.   Tests for any extension loaded in  will be run. If you want to isolate tests to only your extension, you can exclude groups of tests within the  file.
 * remove any unwanted  from the   node.
 * add or make sure a  node exists with the following:

List groups
You can get a list of test groups available for a specific configuration by running:

Exclude groups
You can then exclude specific test groups by adding them to the,   node in  : Tests are considered part of a group when an  comment is placed above the class or function.
 * covers any test that has not been given an  comment.
 * phpunit also considers an  comment as an   comment, but   is preferred.