This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Testing and the fly likes EasyMock : AssertionError expected:1, actual:0 error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "EasyMock : AssertionError expected:1, actual:0 error" Watch "EasyMock : AssertionError expected:1, actual:0 error" New topic
Author

EasyMock : AssertionError expected:1, actual:0 error

Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
Hello,
I am trying to test method retrieve() in Class A (I have created dummy code to represent the problem that I am facing). Please see the comments in bold below for my question.


[ May 21, 2008: Message edited by: Santosh Ramachandrula ]

Thanks,
Santosh
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Santosh Ramachandrula:

You don't mock an object that is being created within a method. The only way to do that would be to modify the actual byte code with a library such as BCEL or ASM, replacing the byte code instructions for "B b = new B()" with something else.

A much more viable option is to expose "B" so that you can indeed swap in a test double. For example, you could do something like this:



Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
 
subject: EasyMock : AssertionError expected:1, actual:0 error
 
Similar Threads
org.springframework.ws.client.WebServiceTransportException: Method Not Allowed [405]
Polymorphism? Inheritance getContentPane
Private Constructors
toString is overrides Object Class or TestA
Java compiler error