unit test DAO layer

How to Unit test with JUnit frameworks like Mockito etc and  test DAO layer without effecting the actual oracle database data. How do i mock  and unit test. Is it better to use simple HSQL (or any other sample simple database)as a sample database instead of using real Oracle database?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
This has been somewhat covered in a previous question (which you were involved in too).... http://www.experts-exchange.com/Programming/Languages/Java/Q_28194350.html.

So to re-iterate, for DAO layer you are generally talking about integration tests not unit tests, and so also generally you have no need for mock objects and Mockito etc.

You generally do these integration tests with your DAO layer connecting to a real database. You could use something like HSQL depending on how complex your queries are and what database functionality they use. The problem is that different databases often function in quite different ways. One example is null/empty string handling, I know Oracle makes no distinction between the two. You can insert and empty string but when you read it back you will get null. Other databases (and I think that includes HSQL) DO differentiate between the two. Also your queries may use functions that are specific to Oracle and so they just might not work at all on another database.

This is why I do all my tests on Oracle, on the same version as in production. However, I have different instances and schemas from the production data that I run my tests against, so that I don't affect anything important.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.