2

I am trying to run only unit test for my custom module.

./vendor/bin/phpunit -c ./web/core ./web/modules/custom/testing_example --testsuite=unit .
But I keep getting the following error:

There were 2 errors: 1) Drupal\Tests\testing_example\Kernel\ExampleFixtureManagementTest::testNodeCreation Exception: There is no database connection so no tests can be run. You must provide a SIMPLETEST_DB environment variable to run PHPUnit based functional tests outside of run-tests.sh. See https://www.drupal.org/node/2116263#skipped-tests for more information.

I only want to run PhpUnit tests and not functional/browser tests.

0

Since those tests are grouped by namespace/directory, you can just pass the respective path to phpunit, simply add tests/src/Unit to your existing path.

  • I want to run all the unit tests in the custom modules directory I'm not sure if you mean I can add it as an extra path parameters or this as path/to/module/tests/src/Unit? – awm Jun 24 '18 at 16:18
  • I was wondering about that, but your question specifically mentiones a single module and provides the path to that ;) Not sure if combining testsuite and a path is the problem, I would suggest you create your own phpunit.xml based on the example, adjust the include path and leave out the path in the command – Berdir Jun 25 '18 at 6:11
0

To run only certain tests in phpunit, append --filter (https://phpunit.de/manual/6.5/en/textui.html) in your phpunit call whether directly in cli or in an IDE phpunit config.

To filter to only Unit tests across all modules but exclude Functional and Kernel tests, you can pass in something that matches the well-structured Drupal tests path like @Berdir was getting at like --filter Unit.

I suspect there's a more specific way to narrow it down like --filter tests/src/Unit but I didn't figure it out. I assume one can also combine filters to pick and chose among Unit and Kernel, for instance, but I also didn't play with that. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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