How to run tests in my contrib module? 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?
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 :

&lt;phpunit bootstrap="web/core/tests/bootstrap.php" colors="true"
         beStrictAboutTestsThatDoNotTestAnything="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutChangesToGlobalState="true"
         checkForUnintentionallyCoveredCode="false"
         printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter"&gt;

&lt;php&gt;
  &lt;ini name="error_reporting" value="32767"/&gt;
  &lt;ini name="memory_limit" value="-1"/&gt;
  &lt;env name="SIMPLETEST_BASE_URL" value="http://drupal-8.localhost"/&gt;
  &lt;env name="SIMPLETEST_DB" value="mysql://drupal-8:drupal-8@localhost/drupal-8"/&gt;
  &lt;env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/sites/default/simpletest"/&gt;
&lt;/php&gt;
  &lt;testsuites&gt;
    &lt;testsuite name="testname1"&gt;
      &lt;directory&gt;web/modules/custom/your_module/tests&lt;/directory&gt;
    &lt;/testsuite&gt;
    &lt;testsuite name="testname2"&gt;
      &lt;directory&gt;web/modules/custom/your_module2/tests&lt;/directory&gt;
    &lt;/testsuite&gt;
  &lt;/testsuites&gt;
&lt;/phpunit&gt;


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 ) :

&lt;testsuite name="toolbar"&gt;
    &lt;directory&gt;./web/modules/contrib/admin_toolbar/tests/src/FunctionalJavascript&lt;/directory&gt;
&lt;/testsuite&gt;


Then you can run tests with :

./vendor/phpunit/phpunit/phpunit


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