java EasyMock忽略来自TestedClass的对象调用';方法
我有一个类,其中有一个对象。我正在测试一个调用这个对象的方法,但是如果这个对象与我的测试无关,那么我想忽略它java EasyMock忽略来自TestedClass的对象调用';方法,java,easymock,Java,Easymock,我有一个类,其中有一个对象。我正在测试一个调用这个对象的方法,但是如果这个对象与我的测试无关,那么我想忽略它 Class TestedClass { ObjectX obj; method() { /* some processing */ obj.someMethod().otherMethod(lotofparameters); /* i want to ignore this line in my test */ } } 所以我想测试method(),而不使用
Class TestedClass {
ObjectX obj;
method() {
/* some processing */
obj.someMethod().otherMethod(lotofparameters); /* i want to ignore this line in my test */
}
}
所以我想测试method()
,而不使用参数在obj
上调用这些方法
感谢您使用
createMock
方法模拟它。然后使用anyTimes
方法基本上忽略对它的任何调用
expect(objMock.someMethod())
.andReturn(42).times(3)
我投了一张回执,以防你有什么需要。查看更多信息
编辑(处理第一条评论)
使
someMethod
返回另一个模拟。然后模拟otherObj.otherMethod
。至于参数,请考虑使用我链接到的文档中列出的匹配器。你甚至可以做你自己的配对者,所以也许这可以帮助解决你的问题 实际上,在obj
上,我调用someMethod().othermethod(lotof参数),所以我想省略这些lotof参数