【问题标题】:Arguments are different! wanted论据不一样!通缉
【发布时间】:2021-10-29 13:26:28
【问题描述】:

对于这个之前尚未回答的问题,我们深表歉意。但到目前为止,我还没有解决我的问题。 好吧,假设我有一个下面的类,我想测试方法 checkMail():

public class SupplierRosServiceImpl implements SupplierRosService {

    @Autowired
    private OpeSupplierService supplierService;

    @Autowired
    private OpeSupplierMapper opeSupplierMapper;

    @Autowired
    private OpeSupplierTraceService supplierTraceService;


    private SupplierServiceMapper supplierServiceMapper;

    @DubboReference
    private IdAppService idAppService;

    @Override
    public Map<String, Integer> countStatus(GeneralEnter enter) {
    List<CountByStatusResult> statusResults = supplierServiceMapper.countStatus(enter);
    Map<String, Integer> map = new HashMap<>();
    for (CountByStatusResult item : statusResults) {
        map.put(item.getStatus(), item.getTotalCount());
    }
    for (SupplierStatusEnum status : SupplierStatusEnum.values()) {
        if (!map.containsKey(status.getValue())) {
            map.put(status.getValue(), 0);
        }
    }
    return map;
}

    public Boolean checkMail(String mail,String idStr) {
        QueryWrapper<OpeSupplier> wrapper = new QueryWrapper<>();
        wrapper.eq(OpeSupplier.COL_CONTACT_EMAIL, mail);
        wrapper.eq(OpeSupplier.COL_DR, 0);
        if(!Strings.isNullOrEmpty(idStr)){
          wrapper.ne(OpeSupplier.COL_ID, Long.parseLong(idStr));
        }
       return opeSupplierMapper.selectCount(wrapper) > 0 ? Boolean.FALSE  : Boolean.TRUE;
    }

在我的测试课中我有:

    class SupplierRosServiceImplTest {

         @InjectMocks
         SupplierRosServiceImpl supplierRosService;

         @Mock
         QueryWrapper queryWrapper;

         @Mock
         private OpeSupplierMapper ope;


         @Test
         void ItShouldCheckMail() {

        //when
        supplierRosService.checkMail("myEmailAdress", "123456");
        //then
        verify(ope).selectCount(queryWrapper);
   }

异常告诉:参数不同!通缉: ope.selectCount(querywrapper) 实际调用有不同的论点: ope.selectCount(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper@ba1f559) 有人可以告诉我如何解决这个问题吗?

【问题讨论】:

  • 我遇到的问题是我的测试中抛出的异常。看看我的帖子

标签: java spring unit-testing


【解决方案1】:

我解决了我的问题。问题是它通过传递给我的 QueryWrapper 服务注入来更改实现细节,从而正确地模拟这个。

【讨论】:

    【解决方案2】:

    检查两个类中的导入是否 QueryWrapper 是否来自同一个包,是否似乎从不同包的测试类中导入。

    如果没有,请将您的整个代码与导入一起粘贴。

    【讨论】:

    • 测试和类的导入是相同的
    猜你喜欢
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    相关资源
    最近更新 更多