To overcome this situation, we can use the HSQL in memory database and test against it.
Here is how we can configure using HSQL.
1) Download HSQL DB and put it in your classpath. OR if you are using Maven , you can add that dependency.
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.1</version>
<scope>test</scope>
</dependency>
2) Change the properties in your text file as follows (We can also create another copy of the context file, which connects to HSQL DB)
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>org.hsqldb.jdbcDriver</value>
</property>
<property name="url">
<value>jdbc:hsqldb:mem:testdb</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value></value>
</property>
3) In the same file, add the following under 'hibernateProperties'. (This will create the tables in memory based on the already existing hbm files in your project)
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</property>
4) Now run the same JUnit test using the loading the new context file instead of old one. This time , the tables are automatically created in memory and the tests are run.
No comments:
Post a Comment