当前位置: 首页 > article >正文

Junit单元测试时提示:Method should have no parameters

 场景

Junit中运行单元测试时提示:

Method XXX should have no parameters

如图:

代码如下:

package com.ws.test.common;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ws.sys.entity.SysEnterpriseOrg;
import com.ws.sys.mapper.SysEnterpriseOrgMapper;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;



public class diguiTest extends ServiceImpl<SysEnterpriseOrgMapper, SysEnterpriseOrg> {

    List<Long> result = new ArrayList<Long>();
    @Test
    public void test(){
        List<Long> canshu = new ArrayList<Long>();
        canshu.add(1l);
        selectChild(canshu);
        for (Long s :result
             ) {
            System.out.print(s);
        }
    }
    @Test
    public void selectChild(List<Long> ids){
        List<Long> temp= new ArrayList<Long>();
        List<SysEnterpriseOrg> sysEnterpriseOrgList = new ArrayList<SysEnterpriseOrg>();
        for (Long id :ids) {
            //查询子级架构
            QueryWrapper<SysEnterpriseOrg> sysEnterpriseOrgChildQueryWrapper = new QueryWrapper<SysEnterpriseOrg>();
            sysEnterpriseOrgChildQueryWrapper.eq("pid",id);
            sysEnterpriseOrgList= this.baseMapper.selectList(sysEnterpriseOrgChildQueryWrapper);
           if(sysEnterpriseOrgList!=null&&sysEnterpriseOrgList.size()!=0){
                for (SysEnterpriseOrg s:sysEnterpriseOrgList) {
                    temp.add(s.getId());
                    result.add(s.getId());
                }
                selectChild(temp);
            }
        }
    }
}

解决

Junit的单元测试@Test不能有返回值和参数。

所以将下面递归函数的@Test去掉即可。

package com.ws.test.common;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ws.sys.entity.SysEnterpriseOrg;
import com.ws.sys.mapper.SysEnterpriseOrgMapper;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;



public class diguiTest extends ServiceImpl<SysEnterpriseOrgMapper, SysEnterpriseOrg> {

    List<Long> result = new ArrayList<Long>();
    @Test
    public void test(){
        List<Long> canshu = new ArrayList<Long>();
        canshu.add(1l);
        selectChild(canshu);
        for (Long s :result
             ) {
            System.out.print(s);
        }
    }

    public void selectChild(List<Long> ids){
        List<Long> temp= new ArrayList<Long>();
        List<SysEnterpriseOrg> sysEnterpriseOrgList = new ArrayList<SysEnterpriseOrg>();
        for (Long id :ids) {
            //查询子级架构
            QueryWrapper<SysEnterpriseOrg> sysEnterpriseOrgChildQueryWrapper = new QueryWrapper<SysEnterpriseOrg>();
            sysEnterpriseOrgChildQueryWrapper.eq("pid",id);
            sysEnterpriseOrgList= this.baseMapper.selectList(sysEnterpriseOrgChildQueryWrapper);
            if(sysEnterpriseOrgList!=null&&sysEnterpriseOrgList.size()!=0){
                for (SysEnterpriseOrg s:sysEnterpriseOrgList) {
                    temp.add(s.getId());
                    result.add(s.getId());
                }
                selectChild(temp);
            }
        }
    }
}




http://www.kler.cn/news/354540.html

相关文章:

  • qiankun 应用之间数据传递
  • linux 开发机与测试机建立 ssh 隧道
  • Vue3的Composition组合式API(computed计算属性、watch监视属性、watchEffect函数)
  • TDengine 3.3.3.0 发布:新增 MySQL 函数与 MongoDB 数据源支持
  • 鸿蒙网络编程系列7-TLS安全数据传输单向认证示例
  • c# FrozenDictionary
  • 基于php的网上购物商场的设计
  • Java第二阶段---09类和对象---第一节 类和对象
  • 【c++ 并发编程】
  • 问题:uniApp 开发测试中的页面回弹效果的问题
  • python基于图片内容识别的微信自动发送信息(对其中逻辑修改一些可以改为自动化回复)
  • 智能伺服,精准控制:匠芯创科技M6800系列方案助力工业升级
  • Redis——事务
  • OpenAI研究揭示ChatGPT的性别和种族偏见
  • web网页---新浪网页面
  • 12月17-19日 | 2024南京软博会,持续升级中!
  • Spring 概念汇总
  • FPGA中的亚稳态
  • 爬虫逆向-js进阶
  • gitee建立/取消关联仓库