Q: Spring transactional tests - prepare data in BeforeClass I would like to create some data in @BeforeClass and use them in my @Test method. 
After all tests are finished (failed or succeeded), I would like to rollback the data. 
Can this be achieved using the annotations @BeforeClass, @Transactional, without having to clean up the data explicitly? 

A: We had a similar problem here. Our solution was to give each test class an embedded H2 database (just takes a couple of seconds to setup the first one; after that, it's not really noticeable anymore).
That allowed us to load any kind of test data into the database, no need to clean that up after all tests have run.
Each test still gets its own transaction, so after each individual test, the per-class database is rolled back to the original state.
To debug tests, we would annotate the individual test with @Transactional(rollback=false), so we could look at the database with an SQL tool.
Another test would examine all tests classes, looking for this annotation to make sure no one accidentally commits it.
