createSavepoint/rollbackToSavepoint and AbstractTransactionalSpringContextTests
I have a bunch of test methods on AbstractTransactionalSpringContextTests .
We have a fairly complex but common text fixture that is wired in to onSetupInTransaction(). These are db integration tests.
The time taken to setup and teardown of this fixture for each test impacts the time taken to run the full set of test cases (test class).
I am wondering if anyone has experimented with using savepoints to avoid the setup/teardown cost for each test method.
- onSetupInTransaction() sets up a fixture in the db ONCE only for the class and then sets a db savepoint.
- the test method runs and applies mods to the db
- teardownInTransaction() normally does a rollback to the save point only, unless we've done all the tests in which case it rolls back the transaction fully (not sure how you detect when all tests are done)
With this approach we do the expensive setup once per test class.
On each test method execution we just rollback the mods applied on that method - so we are back to where we were before that method started.
Given the fact that each test method is executed on a separate instance of the test class it seems likely that any such solution would rely on a static var or singleton somewhere.