1

I have a custom Drupal 8 module for which I'm trying to create unit tests by following the instructions at https://www.drupal.org/phpunit.

The path of my module is: /modules/custom/dev_module
The path of my tests is: /modules/custom/dev_module/tests/src/Unit

More specifically, in the Unit folder I have a DummyTest.php file with the following code:

<?php

namespace Drupal\dev_module\Tests;

use Drupal\Tests\UnitTestCase;

/**
 * My dummy test.
 *
 * @group dummy_test
 */
class DummyTest extends UnitTestCase {

  public function testDummy() {
    $this->assertEquals(5, 5);
  }

}

When executing the following commands from the terminal (I'm on Mac OS):

 > cd core
 > ../vendor/bin/phpunit --list-groups

My group dummy_test doesn't show up in the listed groups. Any idea why?

1 Answer 1

8

Unit tests must have the following namespace: Drupal\Tests\dev_module\Unit.

For complicated reasons, they also don't show up in the right group but they are all in the PHPUnit group.

To run your unit tests with phpunit, just pass the module folder, that also makes it 10x faster for finding the tests:

./vendor/bin/phpunit -c core modules/dev_module

1
  • Thank you, Berdir. Your suggestion worked. I had noticed the namespace Drupal\Tests\MODULE\Unit; in the examples module but I had changed it since it didn't seem to work. Commented Apr 2, 2016 at 18:37

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.