I installed the conditional_fields module:

the tree is the following:

root project
  - phpunit.xml
  - web
    - modules
      - conditional_fields
        - tests
          - src
            - FunctionalJavascript
            - Unit
              - ConditionalFieldControllerTest.php

and this is the declaration of the php class I want to test:


namespace Drupal\Tests\conditional_fields\Unit;

use Drupal\Tests\UnitTestCase;

use Drupal\conditional_fields\Controller\ConditionalFieldController;

     * ConditionalFieldController units tests.
     * In unit testing, there should be as few dependencies as possible.
     * We want the smallest number of moving parts to be interacting in
     * our test, or we won't be sure where the errors are, or whether our
     * tests passed by accident.
     * @ingroup conditional_fields
     * @group conditional_fields
    class ConditionalFieldControllerTest extends UnitTestCase {

In the phpunit.xml file I wrote this:

<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        <testsuite name="drupal-composer-project tests">

but I get this error:

Fatal error: Class 'Drupal\Tests\UnitTestCase' not found in C:\xampp\htdocs\drupaltest2\web\modules\conditional_fields\tests\src\Unit\ConditionalFieldControllerTest.php on line 21
  • I think you need to use the bootstrap file from phpunit.xml.dist at Drupal root folder not the vendor autoload Commented Sep 21, 2018 at 17:26
  • I changed the path of the autoload file inside phpunuit.xml and I set it to web / autoload.php but the error remains Commented Sep 22, 2018 at 13:40
  • For accuracy web / autoload.php points to the autoload file inside the vendor folder, so it does not change anything Commented Sep 22, 2018 at 14:15

1 Answer 1


You must point in the phpunit.xml file to drupal's bootstrap.php file. See a working phpunit.xml file example for Drupal 8 here: http://cgit.drupalcode.org/permissions_by_term/tree/tests/phpunit.xml.dist

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.