I am writing unit tests for a spring mvc 3.1 application that is not using hibernate.
I want to create tables in an hsql DB via the sql scripts I created to generate the tables in an oracle DB.
I’ve looked around for ways to do this but couldn’t find anything helpful.
Ideally, I’d like to create the tables during setup, execute the tests, and then delete the tables.
Any ideas?
Have you looked at the Embedded Database Support in the Spring docs?
Create your database like this:
(Optionally you can specify a type, but it defaults to HSQL). Add the appropriate HSQL dependencies to your classpath.
The embedded database will be created when the application context is created. By making your test @Transactional, there will be a rollback after each test has been executed, causing the tables to revert to its original, known state before the next test begins. Consequently, there is no need for deleting and recreating the tables per test.