当前使用版本(必填,否则不予处理)

mybatis-plus-boot-starter:3.4.1 mockito-core:3.3.3

该问题是如何引起的?(确定最新版也有问题再提!!!)

在mock 继承mybatis plus的批量新增和修改的方法时报错 mockito报参数不匹配MissingMethodInvocationException:

重现步骤(如果有就写完整)

SpecialVehicleInfoServiceImpl继承了ServiceImpl 测试类中注入需要拦截的service @BeforeAll public static void init() { TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), SpecialVehicleInfo.class); }

@InjectMocks public SpecialVehicleInfoServiceImpl specialVehicleInfoService;

在mockservice的批量新增和修改方法时报错 when(specialVehicleInfoService.saveOrUpdateBatch(anyCollection())).thenReturn(true);

报错信息

org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles);

Also, this error might show up because: 1. you stub either of: final/private/equals()/hashCode() methods. Those methods cannot be stubbed/verified. Mocking methods declared on non-public parent classes is not supported. 2. inside when() you don't call method on mock but on some other object.

Comment From: wkddkw

不知道咋回事 有没有大哥能帮看看 一开始报没有缓存类 找了下issue 加了TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), SpecialVehicleInfo.class) 就开始报这个错误了 我参数mock的anyCollection()不知道问题在哪

Comment From: wkddkw

MyBatis-Plus mockito  mybatis-plus 好像是因为调用InjectMocks注解将saveOrUpdateBatch认为是自己的方法 mock的这个 MyBatis-Plus mockito  mybatis-plus 就没有问题