@PrepareForTest({User.class}) 在使用mock时,首先要在测试类上加上注解@PrepareForTest({类名.class}),里 的“类名.class”是类里调用的类,需要被mock的类
Public class test{
@Test
public void test_001(){
AA a = new AA();
User u1 = PowerMockito.Mock(User.class);
Whitebox.setInternalState(a,"u",u1);
PowerMockito.when(u1.getName()).thenReturn(value);
}
}
https://blog.youkuaiyun.com/lqadam/article/details/78939161
https://blog.51cto.com/qihoushangshu/1662073