Mybatis-PageHelper icon indicating copy to clipboard operation
Mybatis-PageHelper copied to clipboard

求大神解答!使用Mockito写单元测试怎么mock如下代码?

Open Ailubby opened this issue 6 years ago • 6 comments

文档中有个示例代码:pageInfo = PageHelper.startPage(1, 10).doSelectPageInfo(() -> countryMapper.selectGroupBy());

我想模拟 when(PageHelper.startPage(anyInt(),anyInt())).thenReturn(pageInfo),也就是这种ISelect接口怎么用Mockito测试?

Ailubby avatar Jul 20 '18 02:07 Ailubby

没试过。 需要注意的是,返回结果不是分页插件返回的,是查询方法。

abel533 avatar Aug 05 '18 10:08 abel533

大佬,我也遇到这个问题了,解决了没

CoderHuUestc avatar Nov 01 '18 09:11 CoderHuUestc

没试过。 需要注意的是,返回结果不是分页插件返回的,是查询方法。

拿Ailubby的问题打比方,就算mock了CountryMapper#selectGroupBy()这个方法,也不能得到正确的返回结果:测试的时候mock的方法返回的List大小为0。

cznno avatar Nov 14 '18 06:11 cznno

应该是 mockito 的问题,看到 Mockito项目中有问这个问题的,但是木有看到什么结果。。

dk980241 avatar Dec 13 '18 07:12 dk980241

同求解决办法

liuhaiyun012 avatar Jul 25 '19 09:07 liuhaiyun012

同求解决办法,这个确实有点恶心人

pysongyg avatar Aug 19 '21 02:08 pysongyg

应该是 mockito 的问题,看到 Mockito项目中有问这个问题的,但是木有看到什么结果。。

有具体链接吗

qingshanyuluo avatar Nov 14 '22 02:11 qingshanyuluo

me too 有什么办法解决吗? 我是mock (countryMapper.selectGroupBy()) 不管我怎么设置返回值,最后都是空的

hujghc avatar May 23 '23 06:05 hujghc