The Site Test module is an extension of the Drupal core SimpleTest module for running site-specific tests in-place on an active Drupal installation. Unlike the core SimpleTest module, which creates a new Drupal installation with a blank database for each test run, SiteTest allows to clone existing database for each test and run it with real-world data and configuration.
SiteTest allows for each test to run in 3 modes:
- Site - use current database tables.
- Clone - create copy of site tables.
- Core - create new tables for blank Drupal installation (core SimpleTest module implementation).
Performance
We've observed 'Core' mode tests that ran in 40s running in 1-2 seconds in 'Site' mode.
Tests in 'Clone' mode run 5-10 seconds longer than tests in 'Site' mode, but it depends on number and size of tables. This performance increase is related to the fact that, unlike 'Core'-mode, no module installation performed for each test run.
Why not SimpleTest contrib module
The SimpleTest contrib module replaces the core SimpleTest module making it difficult to retrofit into existing environment without the risk of breaking existing tests. Site Test takes a different approach in that it sits as a layer between the core SimpleTest module and your site tests. You still can run standard SimpleTest tests using core SimpleTest module and run Site Test tests independently.
Requirements
This module requires the following modules:
- Simpletest (core)
Recommended modules
- site_test_helpers - a set of Drupal site testing helpers to speedup authoring of tests.
- site_test_rest - Drupal module to mock REST responses in tests.
- Devel (https://www.drupal.org/project/devel)
Use Devel to generate content for use in tests with pre-filled fields and 'lorem ipsum' content.
Writing your first test
- Enable the site_test module on your site.
- In a custom module or feature, create a new folder called 'tests'.
- Copy the file 'site_test.example.test' from the site_test/examples folder into your modules test folder and rename to suit the objective of your test.
- Change the getInfo values to reflect the nature of your test.
- In your modules .info file add the test file using: files[] = tests/site_test.example.test
- Clear cache and visit admin/config/development/testing/site_test to run your test.
Test modes
Within the getInfo() test definition of your test there is a mode property which
allows you to set whether your test runs on the current instance, a cloned
instance or a fresh Drupal installation.
- Site mode (site)
Run the test directly on your site, with the current database and files. This
mode is extremely fast and is best for most tests however if you're precious
about your database you will need to clean up after yourself or ensure your
test doesn't add any unwanted data. - Clone mode (clone)
For each test run, the system will clone the current site as a whole into
prefixed tables on the same database and run the tests on a sandboxed version
with the exact same data and configuration. This method is slow for large
databases but generally much faster than the core method and will not affect
your database or site configuration. - Core mode (core)
For each test run, the system will build a fresh installation of Drupal in
prefixed tables. This is the way in which the core SimpleTest module runs and
all site configuration (including enabling modules) must be done individually
for each test. This is the slowest and most cumbersome mode and doesn't allow
for doing complex business logic test case that depends on replicating
complex site conditions.
Project information
- Module categories: Developer Tools
- 4 sites report using this module
- Created by codesidekick on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Development version: 7.x-1.x-dev updated 4 Apr 2016 at 05:33 UTC