Unit testing the hibernate mapping file
Just curious to know if there is any framework that helps to test the hibernate mapping schema.
I've found ORMUnit, used in "POJOs in Action", but it doesn't seem to be in use much. Is there any other framework that people use to ma开发者_StackOverflowke sure that the classes are mapped properly to the database schema, or is this something that people don't really need?
Have a look at Unitils: http://www.unitils.org/
You can use the following:
HibernateUnitils.assertMappingWithDatabaseConsistent();
See the documentation on the website on how to set up Hibernate + Unitils.
Its the type of thing you dont really need. If you test your persistence layer, you are implicitly testing your mapping. You are validating that all columns in the mapping map to columns in the db, that the relationships are set up correctly etc. Any IDE should validate your mapping against the schema, so you know your mapping is syntactically correct.
Testing also gives you a backup for understanding your persistence semantics, e.g. given my cascade settings, will the delete cascade down? Will creating an orphan cause it to be deleted, etc...When I worked with hibernate most tests were in the persistence layer, for exactly this reason.
You could try DBUnit, to test your data access layer as a whole.
DBUnit
精彩评论