Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module speeds up Drupal tests by caching the results of setup methods when using SQLite as the database. It allows test setup steps to be executed only once for the entire test suite, rather than before every single test method.

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
10 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Slowing

Releases

Version Type Release date
1.0.5 Stable Aug 28, 2025