"Alexandre Martins" <[EMAIL PROTECTED]> wrote on 12/06/2007 15:25:25: > Now related to your lower-level tests for database interaction, I > don't know if I got your idea, but I think you wanna test if your > Hibernate mapping is done rightly, is it? Would you mind send me a > piece of this code? Currently I don't write tests to verify Hibernate, > instead I prefer to write acceptance tests, but I'd like to see what > are you doing.
Hi Alex, Client contracts mean I can't send you our code, I'm afraid, but the basic premise is: - Use Spring, get a Hibernate session - Create a domain object, save it - Commit (possibly within an outer transaction, so can rollback after the test) - Load it, check that the reloaded version has the same data as the original. We also check the persistence of relationships between objects. Our behaviour descriptions usually resemble "shouldPersistRelationshipWithChildSheep" and "shouldPersistColourOfWool" (except we're still using JUnit 3, dammit, so it starts with 'test'). My biggest hint is, when you do class equality on Hibernate-loaded objects, use HibernateProxyHelper.getClassWithoutInitializingProxy() - because otherwise, equality depends on lazy-loading, how the object is cached, etc. This also applies to anything in collections, and applies to production code if you do class equality in eg: the .equals() method. That little bug in our code would have been a lot harder to find without these tests! Cheers, Liz. -- Elizabeth Keogh [EMAIL PROTECTED] http://sirenian.livejournal.com http://jbehave.org
