Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When you execute mvn verify then first the unit tests will be executed, followed by the integration tests.  You can run only the integration tests by running mvn failsafe:integration-test.  If you start from a clean checkout, you need to compile them as well: use mvn compile test-compile failsafe:integration-test.

...

Writing tests

If a module extends the database schema, it should preferably have one or more integration tests that perform the module installation and can easily be re-run against different datasources.

Using across-test

There is a package across-test that contains a set of base classes to create test AcrossContext, with some facilities to externalize the datasource that should be created.

Code Block
languagexml
titleMaven dependency for across-test
<dependency>
	<groupId>across</groupId>
	<artifactId>across-test</artifactId>
	<scope>test</scope>
</dependency>

In your unit tests you do not have to take care of creating a datasource yourself.  By importing the AcrossTestContextConfiguration a blank AcrossContext with a valid DataSource will be created.  You can provide one or more AcrossTestContextConfigurer instances to add modules to the context, or modify the context settings.

Code Block
languagejava
titleExample unit test using AcrossTestContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
@ContextConfiguration(classes = ITUserModule.Config.class)
public class ITUserModule
{
	@Autowired
	private UserService userService;	// This is an exposed service from the UserModule
	
	...

	@Configuration
	@Import(AcrossTestContextConfiguration.class)
	static class Config implements AcrossTestContextConfigurer
	{
		@Override
		public void configure( AcrossContext context ) {
			context.addModule( acrossHibernateModule() );
			context.addModule( userModule() );
		}

		private AcrossHibernateModule acrossHibernateModule() {
			return new AcrossHibernateModule();
		}

		private UserModule userModule() {
			return new UserModule();
		}
	}
} 
Info

Using AcrossTestContextConfiguration will always reset the database represented by the datasource before booting up the AcrossContext. Note that due to limitations of the Liquibase "dropAll" script, at time of writing this only drops tables and keys, not stored procedures etc.

Across test datasource

AcrossTestContextConfiguration creates a datasource based on a properties file.  The properties file should be located in ${user.home}/dev-configs/across-test.properties and can contain multiple datasource definitions.  By providing another property acrossTest.datasource, you can specify which datasource from the properties file should be used.  If no acrossTest.datasource property is found, the default is auto which will result in an in-memory HSQLDB being used.

Info

The across-test package currently comes with the jdbc drivers for MySQL, Oracle and SQL Server. For other databases you will still have to provide the driver dependencies yourself.

You can specify acrossTest.datasource as a system property to easily define the datasource at runtime.  If you want to always run a particular datasource locally, you can also put a value for acrossTest.datasource.default directly in the across-test.properties file.

...

languagebash
titleExample: ${user.home}/dev-configs/across-test.properties

...

Integration tests can easily be written using the Across test library, see /wiki/spaces/AX/pages/12648455.

Buildserver datasources

The buildserver is provided with a default across-test.properties containing the following datasources:

...