Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6564873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:01:25+00:00 2026-05-25T14:01:25+00:00

I like to write JUnits for my hibernate dao implementations and seek opinion on

  • 0

I like to write JUnits for my hibernate dao implementations and seek opinion on the suggested approach for writing these unit testcases. I can think of two strategies.

  • Mocking hibernate template using a library like EasyMock and testing just the DAO implementation against these mock objects. (Not really satisfying as I would be testing against a mock layer and not really against test data)

  • Testing against a real test database (an in-memory/external) by writing some test data before running my unit test.

Which approach is a good way of ensuring our DAOs are properly tested. Please point me to any examples on configuring tests using the second approach. I tried looking around but haven’t found the right ones.

Thanks,
Siva.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:01:26+00:00Added an answer on May 25, 2026 at 2:01 pm

    I would follow the second way, using HSQLDB as the DB engine. I think that invoking the real implementation behind a DAO has the positive effect of catching mapping errors.

    If your DAOs have more logic that it’s not related to deal with hibernate (imagine if you DAO loads some objects and then performs some operations on them to return a different object), I would create a different test class to test the methods with extra logic, and mock the methods that return the data. This allows you to set up the data in an easier way rather than priming the DB and immediately loading those objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like to write a process in Worker role, to download (sync) batch of
I'd like to write a game for the Nintendo Wii. How do I go
I'd like to write a script/batch that will bunch up my daily IIS logs
I would like to write a small program in C# which goes through my
I would like to write some data to a file in Ruby. What is
I would like to write a plug-in that will allow a custom written CRM
I would like to write my own OS, and would like to temporarily jump
I would like to write some scripts in python that do some automated changes
I'd like to write some (java) code that takes a PDF document, and creates
I'd like to write an extension method for string, which appears as a static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.