I have a class where I have an object. I am tes开发者_开发百科ting a method that calls this object, but it the object has nothing to do with my test, so I'd like to ignore it.
Class TestedClass {
ObjectX obj;
method() {
/* some processing */
obj.someMethod().otherMethod(lotofparameters); /* i want to ignore this line in my test */
}
}
So I want to test the method()
without calling those methods on obj
with parameters.
Thank u
Mock it using the createMock
method. Then use the anyTimes
method to basically ignore any calls to it.
expect(objMock.someMethod())
.andReturn(42).times(3)
I threw in a return in case you needed it for something. Check out their documentation for more.
EDIT (to address the first comment)
Make someMethod
return another mock. Then mock otherObj.otherMethod
. As for the parameters, consider using the matchers listed in the documentation I linked to. You can even make your own matcher, so maybe that can help solve your issue.
精彩评论