I am wondering how I can speedup my unit tests. I am using JUnit and before each test I am dropping the database schema and then recreating it. Since my schema is somewhat large, this can take quite a long time considering I have over 1000 tests.
To give you an understanding of my setup:
Spring 3 hibernate3.LocalSessionFactoryBean which is using the HSQL dialect.
I am using the JUnit’s Suite runner to run a list of classes.
I noticed that Spring has a SpringJunit4ClassRunner that understands Transaction annotation, but not the suite annotations. I got around this issue and now rollbacks are being attempted, but they seem to cause an infinite recursion which leads to a StackOverflow.
I’m relatively new to Spring and all it’s magic, but I was just wondering if anyone has any ideas in regard to the StackOverflow, or any other ideas in speeding up the testing?
Maybe I could write to a file the clean state of the DB and continuously reload that after each test, though I’m not sure if this is possible.
Thanks in advance.
HSQLDB 2.2.6 supports a statement to clear the data in a database schema.
See the guide here:
http://hsqldb.org/doc/2.0/guide/dataaccess-chapt.html#dac_truncate_statement
Version 2.2.7 and later supports
TRUNCATE SCHEMA PUBLIC RESTART IDENTITY AND COMMIT