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

SpringBoot+Junit在IDEA中实现查询数据库的单元测试

 场景

在IDEA中的SpringBoot项目使用Junit进行单元测试。

1.使用@Test标明的方法不能有参数和返回值。

2.使用@Autowired实现自动注入时需要在测试类上添加注解。

实现

在test目录下新建单元测试类

package com.ws.test.common;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ws.sys.entity.SysEnterpriseOrg;
import com.ws.sys.mapper.SysEnterpriseOrgMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;import java.util.ArrayList;
import java.util.List;@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@WebAppConfiguration
public class diguiTest  {@Autowiredprivate SysEnterpriseOrgMapper sysEnterpriseOrgMapper;List<Long> result = new ArrayList<Long>();@Testpublic 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.toString());sysEnterpriseOrgList= sysEnterpriseOrgMapper.selectList(sysEnterpriseOrgChildQueryWrapper);for (SysEnterpriseOrg s:sysEnterpriseOrgList) {temp.add(s.getId());result.add(s.getId());}}if(temp.size()!=0&&temp!=null)selectChild(temp);}
}

http://www.xdnf.cn/news/995023.html

相关文章:

  • 代码训练LeetCode(32)Z字形变换
  • chrome138版本及以上el-input的textarea输入问题
  • 鸿蒙北向应用开发:新增ts文件出现的问题
  • 【狂飙AGI】第1课:大模型概述
  • QT+VTK 中QWidget与QVTKOpenGLNativeWidget的使用
  • python打卡第52天
  • 如何从 Ansys SpaceClaim 模型中提取 CAD 数据,该模型是在我计算机上安装的未来版本中创建的?
  • Kafka问题排查笔记
  • 全局搜索正则表达式grep
  • 用volatile修饰数组代表什么意思,Java
  • physicsnemo开源程序是开源深度学习框架,用于使用最先进的 Physics-ML 方法构建、训练和微调深度学习模型
  • 接到数据分析任务后,怎么判断是分类还是回归?什么时候你该考虑换模型?
  • Centos8 安装 达梦数据库
  • OpenLayers 加载格网和经纬网
  • STM32通用定时器TRC含义解析
  • 【数据传输常用命令】:服务器与本地之间的数据传输
  • FastDFS分布式储存
  • 保诚发布PRUD币,重塑Web3健康金融生态版图
  • 【AI应用开发数据基建】从非结构化数据到结构化知识的通用转化流程
  • 达梦数据库适配的 Druid 连接池深度优化指南
  • 远程管理命令:网卡和IP地址的概念
  • uni-app项目实战笔记3--使用scroll-view实现每日推荐左右滑动效果
  • Notepad++如何列选
  • 【idea】工具使用报错记录
  • 解决 IntelliJ IDEA 中无法选择 application 模块类路径的问题
  • OpenCV——图像金字塔
  • CVE-2020-1938源码分析与漏洞复现(Tomcat 文件包含/读取)
  • 【自建grafana接入阿里云sls】
  • 力扣HOT100之终章:一些随笔
  • LeetCode 3423.循环数组中相邻元素的最大差值:遍历(模拟)