Running PHPUnit tests within PhpStorm

Last updated on
7 February 2024
  1. Duplicate the /core/phpunit.xml.dist file and rename the copy to /core/phpunit.xml.
  2. Edit /core/phpunit.xml and add the site's database credentials in the SIMPLETEST_DB variable. (Without this step all tests that require a database will be ignored.)
  3. Open to PhpStorm's settings/preferences: File > Settings.
  4. Create a Test Framework configuration by navigating within settings to  PHP > Test Frameworks. Click "+" button, select "PHPUnit local" from dropdown.
  5. Select Use Composer autoloader.
    1. 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
  6. Click OK.
  7. Go to Run > Edit Configurations.
  8. Click the plus sign in the top left corner of the screen and select PHPUnit.
  9. 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.
  10. Click OK.
  11. 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: