《Java单元测试实战》——基础知识:Java单元测试技巧之PowerMock(1) https://developer.aliyun.com/article/1232480?groupCode=java
二、 mock语句
1. mock方法
声明:T PowerMockito.mock(Class clazz);
用途:可以用于模拟指定类的对象实例。
当模拟非final类(接口、普通类、虚基类)的非final方法时,不必使用@RunWith和@PrepareForTest注解。当模拟final类或final方法时,必须使用@RunWith和@PrepareForTest注解。
注解形如:
@RunWith(PowerMockRunner.class)
@PrepareForTest({TargetClass.class})
1) 模拟非final类普通方法
2) 模拟final类或final方法
2. mockStatic方法
声明:PowerMockito.mockStatic(Class clazz);
用途:可以用于模拟类的静态方法,必须使@RunWith和@PrepareForTest注解。
《Java单元测试实战》——基础知识:Java单元测试技巧之PowerMock(3) https://developer.aliyun.com/article/1232478?groupCode=java


