Rollback changes in test after manual interaction with the datasource?

242 Views Asked by At

I'm using dbsetup for my db tests. The problem is I can't manage to get data rolled back after each test using the aproach which have always worked which is annotating the test case (or method) with @Transactional annotation. I suppose this happens because dbsetup uses the DataSource itself so Spring can't get track of what's being done to the database. How to make this work?

1

There are 1 best solutions below

0
On

DbSetup is not tight to Spring in any way. It gets a JDBC connection from a DataSource and commits it when it's done.

The recommended way of using DbSetup is to clear and populate the tables before each test. Using a DbSetupTracker allows avoiding useless repopulations in case a test uses the same data as a previous test, and this previous test hasn't altered the data. This is described in the user guide.