Test data in an Across based application

Often we need our applications to have some test data available in non-production environments, example is a set of predefined users with specific permissions that exist only in integration test setups.  When your application is built around Across modules, you can easily use installers to create the test data, be it using existing services or liquibase scripts.   

There are largely 2 cases I can think of:

A module defines its own set of test data that can be installed.

In this case the module contains the test data installers.  Using any type of property, the configuration can tell the module that the test data installers should run.  Some possible implementation strategies:

  • using the prepareForBootstrap hook the module checks if the property is set, and adds the test data installers to the installer list
    • In this case the installers themselves do not have any special condition checking.
  • by wiring the Environment in the installers, they can check if a certain property is active and decide to do nothing or actually create test data
    • This would probably require the installer to have a RunAlways run condition.

An application wants to install some test data for a certain environment.

 In this case the test data spans multiple modules and is pretty much application specific.  This is probably the most common scenario and the easiest way here is to create a separate test data module that has all the installers.  In the application configuration it is simply a matter of activating the module or not.  The check for test data installation is done in a single spot and one time only.

The installers could use all exposed services from the other modules, but alternatively the test data module could inject additional installers in the specific modules as well (using the prepareForBootstrap hook).  The latter would only be really useful if you need to use non-exposed services, which in turn would require knowledge of the inner workings of the module.

The advantage of using installers is that the application will correct itself upon startup. This can make a database copy from production to a test environment easiers for example. All scripts to clean-up production data, add test data could be contained in installers. After a database restore the installers will run as their installation records will not be present in the database. There is no dependency on external scripts.