Meaningless Drivel is fun!
The moose likes Testing and the fly likes newbie question on easyMocking the DataSource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "newbie question on easyMocking the DataSource" Watch "newbie question on easyMocking the DataSource" New topic

newbie question on easyMocking the DataSource

Aris Tan

Joined: Aug 05, 2005
Posts: 13
Hi, I'm trying to unit test a function with jdbc access

But I'm getting a null on dataSource.getConnection(). What am I missing? Appreciate any help.
[ June 23, 2008: Message edited by: Aris Tan ]
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Before you pass the mock object to the code under test, you need to move it from "record" to "replay" mode with EasyMock#replay(Object... mocks).

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Jonny Andersson
Ranch Hand

Joined: Sep 07, 2004
Posts: 87
You that have posted these messages seem to understand how to use mock object frameworks like EasyMock, and there are a number of other frameworks listed at ... I have some very basic questions. I understand the idea behind use of mock objects despite I lack experiences from it, and I understand use of unit testing and I like test-driven, test-first, development more and more as more I have tried it. But I don�t understand how I should use the mock object frameworks, and not what of them I should look at. Is it possible to say which of them that have got best reputation?

I have looked a little (very little) at EasyMock 2.4 (they do also have a EasyMock 2.3 Class Extension, I am not sure about the difference between them) and on Mock Objects 0.9. It also seems that the maintenance of these frameworks has come to nothing now.

Well, I guess my question could be simplified as should I use mock objects, which one should I then use, adnd how do I learn the basics?

I am currently exercising unit testing on 1.4 servlets as mean to learn more about how to use mock objects in unit testng.

Truly agile Java application developer with Extreme Programming and high quality craftsmanship
Jonny Andersson
Ranch Hand

Joined: Sep 07, 2004
Posts: 87
After some more googling did I find this little good introduction to EasyMock which gives a good idea on how EasyMock can be used. It is easy enough to to get a quick start but more tutorial that builds in this start would have been great. This tutorial is any way a good start for them like me not have learnt how to "think" to fully understand mocking yet
I agree. Here's the link:
subject: newbie question on easyMocking the DataSource
jQuery in Action, 3rd edition