Mock测试

用PowerMock mock static方法

在编写代码时,经常需要调用别人已经写好的工具类,而这些工具提供的方法经常是static方法,在这里,直接贴出《PowerMock实战手册》中的例子 待测试方法: public class EmployeeService { public int getEmployeeCountWithStatic() { return Employ...

PowerMock学习(三)之Mock局部变量

编写powermock用例步骤: 类上面先写这两个注解@RunWith(PowerMockRunner.class)、@PrepareForTest(StudentService.class) 先模拟一个假对象即studentdao方法中的局部变量 用无参的方式new对象 再模拟这个对象被调用时,是否有返回,有返回值给出默认值,没有用doNothing(...

Java单元测试 Http Server Mock框架选型

背景动机 某期优化需要针对通用的HttpClient封装组件--HttpExecutor在保证上层暴露API不动的前提做较多改动,大致包括以下几点: apache http client 版本升级 HttpClientBuilder代码重构 RequestBuilder代码重构 自定义RetryHandler HttpContext扩展 自定义HttpR...