• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Automated Testing with HSQL & Hibernate

 
Ranch Hand
Posts: 511
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again,

Let's say one has an entire DB system based in Hibernate, is it easy conduct automated unit testing of the data by using HSQL?

Any references to tools, APIs, books, and URLs are greatly appreciated!

Happy programming,
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you mean integration test then yes it's relatively simple: You set up a base class for HSQL-based integration tests that has a setUp method initialize a Hibernate SessionFactory against a connection to an in-memory database.

There's going to be stuff about just this in the data access chapter of my upcoming TDD book. It's not yet in print, though, so that's probably not the answer you were hoping for...
 
Unnsse Khan
Ranch Hand
Posts: 511
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lasse,

Hope all is going well for you!

Can you please give me an example (with some code) of what you are talking about?

This is what I have so far:

TestSchema:



Inside the TestSchema.java file there's this snippet of code:



Am trying to invoke this to "auto-generate" tables...

HibernateUtil:



Ant targets:



Am I going about this the right way? Where do I put the setUp() method? How do I tell it which classes I am going to be testing?

With thanks,
[ March 12, 2007: Message edited by: Unnsse Khan ]
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the abstract base class I've used as an example in the book:


The above base class basically provides a static getter for a Hibernate SessionFactory, configured using a properties file named "hibernate.test.properties". The properties file needs to be in the class path and you can put it into the root of the source tree where you have your integration test source code.

Now, a concrete test case class would use the above base class as follows by passing a SessionFactory obtained from the base class to the data access object being integration tested:
 
Unnsse Khan
Ranch Hand
Posts: 511
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lasse,

Thank you very much!

This is some really good code!

We already do this sort of thing (using DAOs for unit testing against Hibernate) at my current job...

I was looking for code that would automate it into HSQLDB...

Was looking for something which was more on the lines with this article.

Happy Programming,
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic