I am trying to run a PHPunit test for my extension but I keep getting the following error:
Fatal error: Class 'PHPUnit_Framework_BaseTestListener' not found in C:\xampp\htdocs\myDrupalsite\sites\all\modules\civicrm\Civi\Test\CiviTestListener.php on line 17
Any ideas on how I can fix this?
I am using CiviCRM 4.7
CMS is Drupal 7
My system OS is Windows 10. My extension is placed in <Drupal root>sites/default/files/civicrm/ext
My test directory was created using civix generate:test on the Windows command prompt.
I run the tests using PHPUnit via the command prompt in the root directory of my extension.

  • Hi Fanan, welcome to CiviCRM Stack Exchange. It helps if you add more detail to your question. Standard is the used CiviCRM version and the accompanying CMS. For this question, you can add how you run the test and more details about your development environment. Mar 3, 2018 at 14:54
  • Hi Fanan, impressive that you have it running on Windows. Mar 7, 2018 at 10:22

2 Answers 2


I run tests the following way

  1. I test in a CiviCRM instance that is generated with buildkit (the toolchain provided for CiviCRM developers see https://docs.civicrm.org/dev/en/latest/tools/buildkit/ .
  2. My tests are generated with civix generate:test. Remarks that this generator also creates the file tests/phpunit/bootstrap.php that takes care of the class loading.
  3. I run the test from the extension directory by executing phpunit4 (This version is installed with buildkit).
  • 1
    This worked fine although when I use phpunit instead of phpunit4 I still get the error Fatal error: Class 'PHPUnit_Framework_BaseTestListener' not found in ...
    – Fanan Dala
    Mar 6, 2018 at 15:34

This sounds like a mismatch in the phpunit versions:

  • Currently, most of the Civi testing runs against the PHAR build of phpunit v4.
  • phpunit v6 renames every class to use \ instead of _, which means that all the base-classes disappear if you run on a newer build of phpunit.
  • Thanks Tim, this gives a good motivation why phpunit4 is used. Mar 7, 2018 at 10:20

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.