sometimes, we need to mock void method like this:
public void printLine() {
//... ...
}
how to mock it by using mockito ?
here it is:
Mockito.doNothing().when(handler).printLine();
sometimes, we need to mock void method like this:
public void printLine() {
//... ...
}
how to mock it by using mockito ?
here it is:
Mockito.doNothing().when(handler).printLine();
在真实的测试当中,并不能所有的逻辑都可以自己控制,因此有了mock测试。今天就结合场景来讲一下怎么做mock测试。 适合对象:初次尝试集成和使用mockito进行单元测试的开发同学 Mock框架的集成这里选择的是Mockito + PowerMockito。为什么会集成PowerMockito,是因为有个想要mock的方法是static方法。这个需要PowerMockito
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M