Change record status: 
Project: 
Introduced in branch: 
10.2.x
Introduced in version: 
10.2.0
Description: 

A new GenericModuleTestBase has been added so that core and contrib modules can test basic functionality like install and uninstall without duplicating code.

Most modules should be able to implement an empty subclass of the test:

namespace Drupal\Tests\my_module\Functional;

use Drupal\Tests\system\Functional\Module\GenericModuleTestBase;

/**
 * Generic module test for my_module.
 *
 * @group my_module
 */
class GenericTest extends GenericModuleTestBase {}

If your module adds content as part of the install process, you will need to implement the optional preUninstallSteps() method, for example workspaces deletes all workspaces prior to uninstall:


namespace Drupal\Tests\workspaces\Functional;

use Drupal\Tests\system\Functional\Module\GenericModuleTestBase;

/**
 * Generic module test for workspaces.
 *
 * @group workspaces
 */
class GenericTest extends GenericModuleTestBase {

  /**
   * {@inheritdoc}
   */
  protected function preUninstallSteps(): void {
    $storage = \Drupal::entityTypeManager()->getStorage('workspace');
    $workspaces = $storage->loadMultiple();
    $storage->delete($workspaces);
  }

}
Impacts: 
Module developers