1

Currently I am able to run the Unit test from the below command

C:\Acquia_dev_desktop\LocalInstance\drupal_new_lab\vendor\bin>phpunit -c 
 ../../core/phpunit.xml.dist ../../modules/custom/lse_demo/tests/src/Unit

PHPUnit 6.5.0 by Sebastian Bergmann and contributors.
......                                                              6 / 6 
(100%)
Time: 10.62 seconds, Memory: 6.00MB
OK (6 tests, 12 assertions)

But When I tried to do the same with Kernel test I get below error

C:\Acquia_dev_desktop\LocalInstance\drupal_new_lab\vendor\bin>phpunit -c ../../core/phpunit.xml.dist ../../modules/custom/lse_demo/tests/src/Kernel
PHPUnit 6.5.0 by Sebastian Bergmann and contributors.

EEEEEE                                                              6 / 6 (100%)

Time: 11.43 seconds, Memory: 6.00MB

There were 6 errors:

1) Drupal\Tests\lse_demo\Kernel\DefaultControllerKernelTest::testDefaultController with data set #0 ('work', 'User', 'Welcome User to Work')
PHPUnit\Framework\Exception: PHP Fatal error:  Uncaught PHPUnit\Framework\Exception: Could not read "../../core/phpunit.xml.dist".

  thrown in C:\Acquia_dev_desktop\LocalInstance\drupal_new_lab\vendor\phpunit\phpunit\src\Util\Configuration.php on line 189

Fatal error: Uncaught PHPUnit\Framework\Exception: Could not read "../../core/phpunit.xml.dist".

  thrown in C:\Acquia_dev_desktop\LocalInstance\drupal_new_lab\vendor\phpunit\phpunit\src\Util\Configuration.php on line 189

PHPUnit\Framework\Exception: Could not read "../../core/phpunit.xml.dist". in C:\Acquia_dev_desktop\LocalInstance\drupal_new_lab\vendor\phpunit\phpunit\src\Util\Configuration.php on line 189
6
  • I usually see it recommended to run the tests from the root directory. Try C:\Acquia_dev_desktop\LocalInstance\drupal_new_lab\>./vendor/bin/phpunit -c core/phpunit.xml.dist modules/custom/lse_demo/tests/src/Kernel Feb 10, 2020 at 14:00
  • I copied phpunit.xml.dist to the root folder with the below configuration. <env name="SIMPLETEST_BASE_URL" value="http://drupaleightsix.dd:8083/"/> <env name="SIMPLETEST_DB" value="mysql://drupaluser@localhost/drupaleightsix"/> And ran the below command, Now I am getting below error G:\Acquia dev desktop\LocalInstance\drupal_eight_six>vendor\bin\phpunit modules/custom/lse_demo/tests/src/Kernel PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. Could you please help me to configure phpunit.xml.dist ?
    – Ashi
    Feb 10, 2020 at 14:38
  • You probably need a password in your connection URL mysql://username:password@localhost/databasename#table_prefix Feb 10, 2020 at 14:56
  • Database does not have a password.
    – Ashi
    Feb 11, 2020 at 6:19
  • 1
    @Ashi usually machine actively refused it means that the service is either not running or runs on different port or network interface. Check that you have MySQL running on 127.0.0.1 and uses 3306 port (default).
    – d70rr3s
    Feb 11, 2020 at 16:03

2 Answers 2

0

Ensure your connection string in the phpunit.php.dist is correct. The correct format is:

mysql://username:password@localhost/databasename#table_prefix
-1

example

put phpunit.xml.dist to root directory

path inside the above file name is

./core/tests/TestSuites/UnitTestSuite.php ./core/tests/TestSuites/KernelTestSuite.php ./core/tests/TestSuites/FunctionalTestSuite.php

./vendor/bin/phpunit --no-coverage UnitTest ./modules/custom/helloworld/tests/src/Unit/helloWorldTest.php

try the same for kernelTest

my test file starts

=====================

namespace Drupal\Tests\helloworld\Unit;

use Drupal\Tests\UnitTestCase; use Drupal\helloworld\Helloworld;

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.