Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use HSQLDB for junit testing cloning a mySQL database

Tags:

java

mysql

hsqldb

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

like image 953
techsjs2013 Avatar asked Nov 30 '25 04:11

techsjs2013


1 Answers

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 {
like image 76
Manuel Quinones Avatar answered Dec 02 '25 17:12

Manuel Quinones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!