Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

Test suites are slow because they set up everything before every test method. In large projects the setup methods, especially from base classes, are called thousands of times. With Sqlite as the database the results of the setup methods can be cached and this is what this module does.

How to use it

  • Download the module. There's no need to enable it, the base class just needs to be there in the codebase.
  • Set the SIMPLETEST_DB environment variable to an sqlite file location (e.g. sqlite://localhost//dev/shm/test.sqlite - this stores the database in memory).
  • Create your test class extending SqliteCachedKernelTestBase, e.g. class MyAppTestBase extends SqliteCachedKernelTestBase.
  • Do not override the setUp method in any of your test classes that are based on SqliteCachedKernelTestBase.
  • Instead, use the two methods described below.
  • Do not call parent::setUpDatabase or parent::setUpClass in any of your test cases. The parent methods will be called automatically by the base class.
  • After changing any of the setUpDatabase methods delete the cached files (their names start with cache-). If you're using docker and the SIMPLETEST_DB is in /dev/shm then restarting the container will be enough.

setUpDatabase

Put all your installation code here, e.g. installConfig, installSchema, installEntitySchema, etc. This method will be fired only once for the whole testsuite.

Note

Don't assign values to any class properties in this method. They won't be there when the test runs.

setUpClass

This is the place for setting up the class. Things like $this->entityTypeManager = $this->container->get('entity_type.manager'); can be added here. The method is called before every test (like the regular setUp method).

Known issues

In some cases the first test in a class may fail with an error unrelated to the subject matter. That's caused by static caching in core. Adding an empty test method at the beginning of the class forces a re-load with the cached database and makes the next tests work as expected.

Activity

Total releases
1
First release
Aug 2025
Latest release
7 months ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.5 Stable Aug 28, 2025