Glide
Glide

Reputation: 21275

Speed up Integration Test Suite

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.

Upvotes: 1

Views: 884

Answers (1)

Gary Russell
Gary Russell

Reputation: 174799

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

See the Integration Testing Chapter for complete information.

Upvotes: 1

Related Questions