Writing Automated tests in Drupal 9

This is a start.

Install PHP Unit: PHPUnit8.4+ for Drupal 9

composer require --dev phpunit/phpunit ^8.4

For the current portal, add core-dev option

composer require 'drupal/core-dev:^9.5'
composer update

Drupal requires Prophecy PhpUnit when using PHPUnit 9 or greater.

composer require --dev phpspec/prophecy-phpunit:^2'

When using older versions of Drupal with PHPUnit9, the phpunit.xml schema may need to be updated. Run that via.

vendor/bin/phpunit -c web/core/phpunit.xml web/modules/custom/ji_custom_test/tests/src/Functional/JICustomLabsConfigFormPageTest.php  --migrate-configuration

To execute individual or site specific tests execute the following. Using a sudo -u username can take care of permissions issue for creating folders

sudo -u www-data  ../vendor/bin/phpunit -c core/phpunit.xml modules/custom/ji_custom/tests/src/Functional/JICustomPagesTest.php

Execute Units tests of specific group.

sudo -u www-data  ../vendor/bin/phpunit -c core/phpunit.xml modules/custom/ji_custom_test/tests/   --group ji_custom

Groups can be set by adding an annotation @group in the test function

/**
  * @group ji_custom
  * @return void
*/
public function testHPLCStatus(): void {
}

--
https://dri.es/phpunit-tests-for-drupal
https://deninet.com/blog/2018/12/31/writing-automated-tests-drupal-8-par...
https://www.drupal.org/node/2116263
https://www.drupal.org/docs/testing/phpunit-in-drupal/phpunit-browser-te...
https://www.lullabot.com/articles/an-overview-of-testing-in-drupal-8
https://phpunit.de/getting-started/phpunit-9.html
https://www.drupal.org/docs/automated-testing/phpunit-in-drupal/running-...