Abhijeet Kashnia
Abhijeet Kashnia

Reputation: 12880

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 make sure that the classes are mapped properly to the database schema, or is this something that people don't really need?

Upvotes: 1

Views: 1383

Answers (3)

Wilhelm Kleu
Wilhelm Kleu

Reputation: 11047

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.

Upvotes: 2

hvgotcodes
hvgotcodes

Reputation: 120168

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.

Upvotes: 2

lucas1000001
lucas1000001

Reputation: 2750

You could try DBUnit, to test your data access layer as a whole.

DBUnit

Upvotes: 0

Related Questions