I am working on a spring webflow project and I am thinking can I use HSQLDB and not my mysql for junit testing?
How can I clone my mysql database into HSQLDB
If you are using spring 3.1 or greater you could use spring profiles to achieve this. The default profile is loaded when no active profile is set.
<beans profile="dev">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="org.hsqldb.jdbcDriver" />
...other datasource properties also create or drop db
</bean>
</beans>
<beans profile="default">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
...other datasource properties
</bean>
</beans>
In your unit test set the active profile by adding the annotation.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:app-config.xml")
@ActiveProfiles("dev")
public class TransferServiceTest {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With