Monday, February 4, 2008 10:58 AM
I went down the same path a while back, trying to connect to a database to test my classes. Unfortunately I also realized I couldn't control the order my test cases ran. This meant I couldn't guarantee the data's integrity and my tests were difficult to work with.
I ended up using DBUnit to get around this issue. DBUnit can be used to automatically populate a database with 'test' data that gets reloaded before each single test. This allows each test to run on a known set of starting data, and updates/deletes won't break tests if they run out of order. Since the data is always reloaded before a test, it's clean.
With all that said, I created my own TestCase object that includes all the DBUnit code. So I simply subclass this test and write my specific tests there. From there I just configured Hibernate to hit the database using the hibernate-cfg.xml as normal.
If you're interested I can post pertinent source for your reference. It doesn't address your original issue, but will give you a pretty flexible alternative...