views:

174

answers:

4

In my project I can successfully test database code. I'm using Spring, Hibernate, HSQLDB, JUnit and Maven.

The catch is that currently I have to launch HSQLDB manually prior to running the tests. What is the best way to automate the launching of HSQLDB with the technologies being used?

A: 

With JUnit, you can create a method that is executed before your tests using the following annotation: @Before

The link to the JUnit docs about it is here: JUnit FAQ - Test Fixtures

Chris J
A: 

Use it in-process or in memory and it will get started from JDBC when establishing a connection.

Pascal Thivent
A: 

You can also run an Ant task <startdb>:

https://forums.hibernate.org/viewtopic.php?f=6&amp;t=984383&amp;start=0

duffymo
+1  A: 

I am assuming that with hsql you are referring to HSQLDB.

Configure your database url for JDBC drivers (for hibernate etc) to embedded memory based version of HSQLDB:

jdbc:hsqldb:mem:myunittests

Then a inprocess version of HSQLDB automatically starts that stores stuff to memory. No need to start any external servers.

Juha Syrjälä
Thanks, just getting started with HSQLDB. The tutorial I was following was configured for using a server. Changing to use in memory solves my problem.