File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes mocking database using easymock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "mocking database using easymock" Watch "mocking database using easymock" New topic

mocking database using easymock

mrunalini two

Joined: Nov 30, 2009
Posts: 1
my google search failed.

Am a newbie and I want to study mocking database (no specific target like connections, resultsets) through an example.

Would anyone please provide some hello world thing on mocking database/sql code using EasyMock?

Anything is OK as I am just a learner.
Jelle Klap

Joined: Mar 10, 2008
Posts: 1951

I'd forget about mocking an entire database. If you adopt the Data Access Object (DAO) to abstract and encapsulate access to the database, such an object would be a convenient candidate for a test double (possibly using EasyMock). Eventually you'll want to unit test the DAO itself, and then it would make sense to utilize some sort of ligthweight in-memory database, instead of the heavyweight (network accessed) production database server, and employ a library like DbUnit. That's as far as I'd take it for the purpose of unit testing. Eventually, though, you'll want to integrate every system component and test against the real thing, but that's well beyond the scope of unit testing.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
I agree. Here's the link:
subject: mocking database using easymock
It's not a secret anymore!