2007-01-25

My new goodie of the month: AbstractTransactionalDataSourceSpringContextTests

I've bought the SpringOne DVD and got it this autumn, but haven't had the time to listen to it before I started on a new project. Finally using the Spring Framework, a really good IDE and an application server that doesn't take forever to start up.

This little project I'm working on doesn't have to much logic on the business tier so what I really wanted was to test the SQL statements. I've tried the mock object approach and as everybody else says: It's not the way to go when testing this kind of code.

When listening to Rod's talk about testing, I had to agree with the statement about using in memory database. When you are testing SQL towards a database, I really want to use the same database as the production environment because of the difference between SQL dialects.

So this really cool, long named class: AbstractTransactionalDataSourceSpringContextTests does a fantastic job solving my testing needs. By utilizing the transaction mechanism in the database, you can issue update and insert statements, getting error messages from the database if something went wrong, and if everything went fine - everything just gets rolled back so my tests are repeatable. Brilliant - just brilliant.

I think that Spring-boys from time-to-time should borrow the slogan from Jetbrains: "Develop with pleasure".....