unit test DAO layer

gudii9 used Ask the Experts™
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?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Business Systems Analyst / Software Developer
Top Expert 2015
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial