Search code examples
hibernatespringmaven-2junithsqldb

What is the best way to launch HSQLDB for unit testing, when working with spring, maven and hibernate?


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?


Solution

  • 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.