2011-03-18 56 views
1

我有一个类,我有一个对象。我正在测试一个调用此对象的方法,但它的对象与我的测试无关,所以我想忽略它。java EasyMock忽略来自TestedClass方法的对象调用

Class TestedClass { 
ObjectX obj; 

    method() { 
    /* some processing */ 
    obj.someMethod().otherMethod(lotofparameters); /* i want to ignore this line in my test */ 
    } 
} 

所以我想测试method()无需调用与参数上obj这些方法。

感谢ü

回答

2

使用createMock方法模拟它。然后使用anyTimes方法基本上忽略对它的任何调用。

expect(objMock.someMethod()) 
     .andReturn(42).times(3) 

我扔了一个回报,以防您需要它的东西。查看their documentation获取更多信息。

编辑(解决第一个评论)

制作someMethod返回另一个模拟。然后模拟otherObj.otherMethod。至于参数,请考虑使用我链接到的文档中列出的匹配器。你甚至可以制作自己的匹配器,所以也许可以帮助解决你的问题。

+0

那么,实际上在'obj'上我调用someMethod()。othermethod(lotofParameters) 所以我想省略这些lotofParameters – myro 2011-03-18 14:52:54