views:

231

answers:

1

Spring Test helpfully rolls back any changes made to the database within a test method. This means that it is not necessary to take the time to delete/reload the test data before each test method.

But if you use the @BeforeClass Junit annotation, then that forces the data loader to be static. A question that is explored here: http://stackoverflow.com/questions/1052577/why-must-junits-fixturesetup-be-static

If the data initialization method is static, so must the data connection methods and the data source..and on and on...forcing everything to be static...which won't work. At which point, I ask - what good is Spring Test's ability to rollback changes when you have to delete/reload the test data anyway for every test??!?!

+2  A: 

Spring Test and DbUnit is two excellent frameworks. But it doesn't make sense to combine them. Since Spring Test execute a rollback on the connection, it cleans up afterwards, while DbUnit cleans up and insert test data in the @Before method.

Use Spring if you're not dependent on any dynamic data and dbUnit otherwise.

Mats
I find DBUnit's ability to load a database table from XML to be convenient. Does Spring Test have a capability like this?
HDave