Running PHPUnit tests within PhpStorm
Last updated on
7 February 2024
- Duplicate the
/core/phpunit.xml.dist
file and rename the copy to/core/phpunit.xml
. - Edit
/core/phpunit.xml
and add the site's database credentials in theSIMPLETEST_DB
variable. (Without this step all tests that require a database will be ignored.) - Open to PhpStorm's settings/preferences: File > Settings.
- Create a Test Framework configuration by navigating within settings to PHP > Test Frameworks. Click "+" button, select "PHPUnit local" from dropdown.
- Select Use Composer autoloader.
- For Path to script, enter the path to your Drupal root directory, followed by
/vendor/autoload.php
.Also set the Default configuration file directly to your Drupal root directory, followed by/core/phpunit.xml
.
- For Path to script, enter the path to your Drupal root directory, followed by
- Click OK.
- Go to Run > Edit Configurations.
- Click the plus sign in the top left corner of the screen and select PHPUnit.
- In the Test runner section: for the Test scope option, select Defined in the configuration file, tick the Use alternative configuration file checkbox, and enter the path to your Drupal root directory, followed by
/core/phpunit.xml
. - Click OK.
- Run the test suite by going to Run > Run ....
You can limit the tests run to a single group of tests by adding the --group
parameter to the Test Runner options. For example, --group Views
will run only the Views unit tests.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion