We are using maven-failsafe-plugin for testing and trying to isolate tests in forks.
I tried using ${surefire.forkNumber} in testContext.xml, but that didn't quite work. The database was not initialized with hibernate.hbm2ddl.auto=create-drop in forks. I'm not sure if each fork actually executed hbm2ddl create.
<context:property-placeholder location="/datasource/${test.datasource:pg-default}.properties, /properties/appInfo.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}${surefire.forkNumber:1}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
At the moment we are using Failsafe 3.2 with Spring 5.3 and Hibernate 5.6.
Oh. We are trying out different things, but at the moment the properties for datasource was: jdbc.url=jdbc:postgresql://appdb.test:5432/test_app. So we are aiming for using test_app1, test_app2... databases in each fork.