I'm writing a contrib module but I can't find the documentation to run the tests - unit and functional. I know that I'm supposed to use PhpUnit, but I can't find examples of PhpUnit configuration files and more importantly, there is no resource on how to execute functional tests - i.e. having the module tested against a running Drupal instance.

I've been looking at some famous contrib modules like Paragraphs and there is nothing about running tests in their documentation - and no phpunit dependency at all. Which doesn't make sense to me since there are some functional tests implemented.

How are we supposed to provide tests for contrib modules?


1 Answer 1


You have to include phpunit/phpunit package in composer, alredy done if you took default drupal installation :

composer require phpunit/phpunit --dev

A file should be filled which describe yours testsuites, generally phpunit.xml

It looks like this ./phpunit.xml :

<phpunit bootstrap="web/core/tests/bootstrap.php" colors="true"

  <ini name="error_reporting" value="32767"/>
  <ini name="memory_limit" value="-1"/>
  <env name="SIMPLETEST_BASE_URL" value="http://drupal-8.localhost"/>
  <env name="SIMPLETEST_DB" value="mysql://drupal-8:drupal-8@localhost/drupal-8"/>
  <env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/sites/default/simpletest"/>
    <testsuite name="testname1">
    <testsuite name="testname2">

In this example, drupal is located in ./web/ directory with ./vendor/, both in root path (./) .

You can add test for contrib module, but they are already tested (if they contain tests) when authors are pushing their sources to drupal.org ( https://www.drupal.org/pift-ci-job/1339317 ) :

<testsuite name="toolbar">

Then you can run tests with :


To use a specific description file :

./vendor/phpunit/phpunit/phpunit -c phpunit-other.xml

To run a specific testsuite :

./vendor/phpunit/phpunit/phpunit --testsuite=testname1
  • I think the essential part here is that you need a Drupal installation that is outside the specific contrib module. Quite inconvenient.
    – donquixote
    Commented Jun 3 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.