0

So I am using easymock to write unit test fpr a method inside my class. I have mocked an object inside this method and it works fine. The problem is inside this test method I have several calls to other methods inside the same class.

For example,

public class testClass { 
    public void testMethod() { 
        mockedObject.method(); --> I define a return type for this and it works fine.
        this.otherMethod() {
        --> Inside this method I have a call to the mocked object with different methods..
    }
}

So my question is that, when the method calls another method by using this.otherMethod() should I define all the return values for the mockedObject calls inside otherMethod? Isn't there a way to specify a return value for otherMethod so that it won't even go inside the other method? Plz note that here this is not the mockedObject and that is why I cannot use eaymock return value for that. I was thinking maybe there might be a way around this.

Thanks.

Update: I found this for partial mocking of methods: http://www.easymock.org/EasyMock2_2_2_ClassExtension_Documentation.html Which helps to only mock specific methods. But when I try to use it, it crosses a line on createMock method.. Sth like wrong syntax!

Alex
  • 8,093
  • 6
  • 49
  • 79
Sara
  • 2,417
  • 7
  • 35
  • 52
  • Show us real indented Java code rather than unindented invalid code. – JB Nizet Jul 23 '12 at 18:06
  • Sorry if I wasn't clear on my question but I found the answer as bellow. Thanks. – Sara Jul 23 '12 at 18:16
  • I wanted to ask a general question I just added more details which wasn't needed. How to isolate method calls inside a test method with easymock. – Sara Jul 23 '12 at 18:22

1 Answers1

0

Thanks everyone,

I found this link: http://fczaja.blogspot.com/2011/11/easymock-create-partial-mocks.html

The answer is to partially mock those methods called within this method to isolate those method calls.

Thanks again.

Sara
  • 2,417
  • 7
  • 35
  • 52