【发布时间】:2012-04-13 06:43:31
【问题描述】:
我有一个实现 InvocationHandler 的类,如下所示:
public class MyProxyClass implements InvocationHandler
{
public Object invoke (Object proxy, Method method, Object[] args) throws Throwable
{
//Do something interesting here
}
}
使用 PowerMock 和 Mockito,我试图在我的单元测试类中传递一个模拟方法对象:
@RunWith(PowerMockRunner.class)
@PrepareForTest({Method.class})
public class MyProxyTest
{
MyProxy underTest;
@Test
public void testInvoke() throws Throwable
{
Method mockMethod = mock(Method.class);
//...
}
}
由于方法是final,我已经完成了@PrepareForTest 的技巧,但这似乎并没有减少它。 这是因为它是自举的吗?我只是在处理这个错误吗?
我一直在查看以下链接,但那里没有确定的内容:
【问题讨论】:
标签: unit-testing junit mocking mockito powermock