Link to home
Start Free TrialLog in
Avatar of dkim18
dkim18

asked on

how to write up a test case on dao methods using mock object?

Hi,

I have DAO java classes with methods doing CRUD operations against DB2.
I would like to create mock object instead of connecting to the actual database.
Since I never done it, I can use some help.
1) say I have getContactList() method returning List<Person> object.
How do I create a mock object and test that mehtod?

ANy good example would be greatly appreciated.
Avatar of gudii9
gudii9
Flag of United States of America image

Here is good explanation, link on that


When you test your service layer you will want to use a mocking library such as Mockito to mock your DAOs and therefore your domain layer. This ensures that they are true unit tests.

http://stackoverflow.com/questions/8601536/junit-to-test-spring-service-and-dao-layer
SOLUTION
Avatar of gudii9
gudii9
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dkim18
dkim18

ASKER

Yes, I am hearing that I should not mock when testing dao/sql related codes.
Someone from my team suggested this since we can't connect from locally but have to move our code to the mainframe.
Another reason was that table return a huge number of of rows.

Since I didn't know much about the mock, I didn't say much but I am reading that mock testing is not appropriate for dao/sql query codes.