wood burning stoves 2.0*
The moose likes Testing and the fly likes EasyMock Vs JUnit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "EasyMock Vs JUnit" Watch "EasyMock Vs JUnit" New topic
Author

EasyMock Vs JUnit

vivek dhiman
Ranch Hand

Joined: Aug 05, 2011
Posts: 111

Hi

I was going through the mocking framework for the testing purpose. Can someone post sample code where i can see test though junit will be not appropriate as compare with easymock.

Thanks
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2833
    
  11

EasyMock is a tool you use in your JUnit tests, not something that replaces JUnit. Are you asking for an example of where EasyMock would be useful?
vivek dhiman
Ranch Hand

Joined: Aug 05, 2011
Posts: 111

Hi Thanks

I have an example, below is the test code.


When I remove the verify method, Test gets Pass but when i apply it gets fail. It shows the assertion error :



Any advice



Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2833
    
  11

Right, you are telling EasyMock that getPrice("EBAY") will be called once on marketMock, and to return 20.0 when that happens. However you try to verify that result before performing any actions that would make the call. Try moving the verify to the last line of the test.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EasyMock Vs JUnit
 
Similar Threads
newbie question on easyMocking the DataSource
how to test struts with Junit
Testing JSP
Object Oriented Testing
EasyMock: mocking a call to the same object