java - Mockito - doCallRealMethod 在springboot应用程序中没有按预期工作
问题描述
对于具有字符串参数的方法,mockito 中的 doCallRealMethod 没有按预期工作(即它被模拟而不是调用真实方法)。我有以下课程
Class A{
@Autowired
Utils utils;
public invokerMethod(String a,String b,String c){
utils.realMethod(a,b,c);
.....
......
}
}
类实用程序:
Class Utils throws Exception{
public void realMethod(String a,String b,String c)
if(a.equals(""))
throw someException();
}
测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
Class ATest(){
@Autowired
A a;
@MockBean
Utils utils;
@Test
public invokerMethodTest(){
doCallRealMethod().when(utils).realMethod(anyString(),anyString(),anyString());
a.invokerMethod("","","");
}
}
我尝试用“”替换anyString,new String()但它仍然不适合我
解决方案
推荐阅读
- gtk - 如何使用 Glade 准备可以在运行时以编程方式创建和填充的 ListBoxRow 模板?
- javascript - 如何在 Vue.js 和 Firebase 中向现有用户添加新数据
- java - 我不知道错误在哪里,我在虚拟机中使用了linux
- docker - “sh”来自命令 $ docker run -it docker.elastic.co/elasticsearch/elasticsearch:7.3.1 sh
- dart - 如何将凸起的按钮定义到材质扩展面板中?
- javascript - Firebase 身份验证、phonegap 构建和 deviceready 事件
- mysql - SQL - 按设备类型获取平均计数
- python - 如何修复 TensorFlow 错误:无法创建 NewWriteableFile
- javascript - 如何在点击事件中获取图像 ID
- hashmap - Splitter EIP 可以拆分 HashMap 还是必须是 List