Announcement Announcement Module
No announcement yet.
createSavepoint/rollbackToSavepoint and AbstractTransactionalSpringContextTests Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.


  • #2
    This is the forum for the Spring Integration project. You're a bit off-topic.

    Why don't you just stick your testdata in the database before you run the whole suite? I can hardly imagine a scenario where you'd need completely different testdata for each test. If you do it the easy way you don't have to tie your tests to a specific infrastructure that supports savepoints.