1
votes

I'm trying to speed up running my integration test suite. For every integration test class I have, it recreates the whole in-memory H2 database from scratch before running the tests - which takes up the most time. All methods I'm testing are within a Spring/Hibernate stack.

Is there a way to avoid recreating the db for each test while ensuring the db is in a clean state?

Some methods I'm testing call methods that start new Hibernate transactions - so not sure if it's possible to begin a new transaction before each test and roll everything back after.

1
Seems like from this post stackoverflow.com/questions/5178708/… there's no easy way to do so and the best solution is to recreate the db after each test. - Glide

1 Answers

1
votes

That is the default behavior (rollback) when using @Transactional with @RunWith(SpringJunit4TestRunner.class).

See the Integration Testing Chapter for complete information.