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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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