Trying TDD with PHPUnit I'm trying out the built in test driven development method in Drupal 8 but I'm running in to a problem..

I'm getting the following errors when trying to run ./core/vendor/bin/phpunit --list-groups ./modules/ in my cli:


  PHP Fatal error:  Class 'Drupal\Tests\UnitTestCase' not found in
      /Applications/MAMP/htdocs/drupal/modules/custom_cookie_compliance/
      tests/CustomCookieComplianceTest.php on line 10
  
  Fatal error: Class 'Drupal\Tests\UnitTestCase' not found in
      /Applications/MAMP/htdocs/drupal/modules/custom_cookie_compliance/tests/
      CustomCookieComplianceTest.php on line 10


I have created a module folder called custom_cookie_compliance in my modules folder. In turn I have a custom_cookie_compliance.info.yml file containing the following.

 name: Custom Cookie Compliance
 description: Displays a cookie compliance information window at the top of the website.
 core: 8.x
 type: module


I also have a tests folder containing a src folder which then contains a CustomCookieComplianceTest.php file with the following code.

&lt;?php
namespace Drupal\custom_cookie_compliance\Tests;

use Drupal\Tests\UnitTestCase;

/**
 * @group cookie
 */

class CustomCookieComplianceTest extends UnitTestCase {
  public function testSetCookies() {
    if (!isset($cookie_set)) {
      $cookie_set = TRUE;
    }

    $this-&gt;assertTrue($cookie_set);
  }
}


I have written the code by following this guide.

I understand it can't find the UnitTestCase class, but the guide says that is should work, so why isn't it?
My guess is that you're not including the phpunit.xml.dist file, which sits in the core folder.

Either run tests from there (./vendor/bin/phpunit ../modules/your_module) or specify that file with -c.

You can also provide your own phpunit.xml.dist file (see the Payment module as an example); then you can run PHPUnit from your module folder.