// 私有方法测试,无参
Method method = PowerMockito.method(TestService.class, "methodName");
method.invoke(testService);
// 私有方法测试,传参
Method method = PowerMockito.method(TestService.class, "methodName", Test1.class, Test2.class);
method.invoke(testService, test1, test2);
// 加注解
@PrepareForTest({XXXUtil.class})
XXXServiceTest {
@Test
public void test() {
// 调用PowerMockito.mockStatic
PowerMockito.mockStatic(XXXUtil.class);
when(XXXUtil.staticMethodName())...
}
}
// 彻底mock某方法(不执行内部语句,public/private都可)
MemberModifier.stub(MemberMatcher.method(TestService.class, "methodName")).toReturn(false);