File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "newbie question on easyMocking the DataSource" Watch "newbie question on easyMocking the DataSource" New topic
Author

newbie question on easyMocking the DataSource

Aris Tan
Greenhorn

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
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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 http://www.mockobjects.com/ ... 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 http://www.michaelminella.com/testing/unit-testing-with-junit-and-easymock-2.html 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: http://aspose.com/file-tools
 
subject: newbie question on easyMocking the DataSource