Closed HeCHieh closed 1 year ago
在你的 given 方法中,定义了入参 page,当 selectPage 传入此参数时返回预先定义的 page 值
given(this.homePopUpConfigMapper.selectPage(page, null)).willReturn(page);
但在实际调用中,com.example.mybatisplusmockdemo.HomePopUpConfigServiceImpl#list
方法中,使用入参自行产生了新的 Page 对象,这两个 Page 对象不是同一个,所以无法匹配和捕获
Page<HomePopUpConfig> page = Page.of(pageDTO.getCurrent(), pageDTO.getLimit());
我通常这么使用,使用
given(this.homePopUpConfigMapper.selectPage(ArgumentMatchers.any(Page.class), ArgumentMatchers.isNull())).willReturn(page);
这是一种比较粗犷的使用方式,如果要精确匹配,可能需要自定义匹配方式,如下
given(this.homePopUpConfigMapper.selectPage(ArgumentMatchers.argThat(homePopUpConfigIPage -> homePopUpConfigIPage.getSize() ==10L && homePopUpConfigIPage.getCurrent() == 1L), ArgumentMatchers.isNull())).willReturn(page);
另外,这个应该是 mockito 的使用问题,感觉提到那边更合适。
如上,走路摔了不要直接怪地不平
当前使用版本(必填,否则不予处理)
该问题是如何引起的?(确定最新版也有问题再提!!!)
测试代码
下面代码没按预期mock值返回
复现代码示例
报错信息
无报错信息