待测试类方法中,有new的对象,之后有逻辑处理,调用另外一个方法给其赋值。之后判断分支需要用到该对象。 测试方法中需要用到 PowerMockito.whenNew(EntAdminResult.class).withAnyArguments().thenReturn(entAdminResult1); 先new一个想要的对象。set其中的属性值,就可以mock该过程了。 当时list时用 PowerMockito.whenNew(ArrayList.class).withAnyArguments().thenReturn(orgIds);

推荐链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: