当我侦察一个物体时如何获得私人方法?

时间:2016-11-01 07:39:20

标签: private powermockito

公共课A. {

[...]
    private int methoda(int i)
     {
        ...
        methodb();
        ....
     }
    private void methodb()
    {...}
[...]

}

试验:

@Test
@PrepareForTest({...})
public void testMethoda() throws Exception
{
     //mytest
     A a = PowerMockito.spy(new A());
     Method privateMethod = a.getClass().getDeclaredMethod("methoda", int.class);
    privateMethod.setAccessible(true);

      PowerMockito.doNothing.when(a, "methodb");
     ..
}

例外: java.lang.NoSuchMethodException

谁能告诉我如何处理这种情况?

0 个答案:

没有答案