Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Sqlite test cache

No security coverage No further development

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.

Drupal 8–10 · not 11

Ask your assistant about Sqlite test cache

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Jan 2023
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 1
Maintenance
Active

Releases

Version Type Core PHP Release date
1.0.5 Stable 8–10 Aug 28, 2025
1.0.4 Stable 8–9 Jan 16, 2023