Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unit test patterns with Hibernate

 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a simple question for folks who have strong experience with using Hibernate. My question relates to best practices in terms of unit testing Hibernate code, particularly when the DAO pattern is used. In general, should unit tests be written just for the DAOs, just for the entities, or for both?

We are beginning a project, and I want to ensure that we provide good test coverage, while at the same time not spending more time than we need. I'd imagine that one answer to my question is "if you want complete coverage, then test the entity and the DAO layer", but I'm curious if, in practice, anyone has found it more efficient to omit tests for one or the other.

Thanks in advance!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't test either unless you have a test generation tool that can reverse engineer tests from your DAOs. Assuming you have a common DAO pattern applied throughout your DAO layer all you will be doing is testing the same relatively small bit of code repeatedly. While this might be a good thing, you could end up with a large set of very basic tests you have to maintain. You will probably get enough coverage just testing the domain objects that use your DAO code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic