若依框架-添加测试类-最新

1、在【ruoyi-admin】的pom.xml下添加依赖

XML 复制代码
        <!-- 单元测试-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>

2、update一下maven(确认单元测试已经添加进来)

3、添加在src下创建test模块(与main同级)

4.创建测试类

XML 复制代码
import com.aide.CMSApplication;
import com.aide.mqtt.parse.domain.DataFile;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest(classes = CMSApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class UnitTest {
	@Autowired
	private DataFile dataFile;

	@Test
	public void test1() {
		System.out.println(dataFile.toString());
	}
}

5.测试结果

相关推荐
架构师沉默1 天前
别又牛逼了!AI 写 Java 代码真的行吗?
java·后端·架构
后端AI实验室1 天前
我把一个生产Bug的排查过程,交给AI处理——20分钟后我关掉了它
java·ai
凉年技术1 天前
Java 实现企业微信扫码登录
java·企业微信
狂奔小菜鸡1 天前
Day41 | Java中的锁分类
java·后端·java ee
hooknum1 天前
学习记录:基于JWT简单实现登录认证功能-demo
java
程序员Terry1 天前
同事被深拷贝坑了3小时,我教他原型模式的正确打开方式
java·设计模式
NE_STOP1 天前
MyBatis-缓存与注解式开发
java
码路飞1 天前
不装 OpenClaw,我用 30 行 Python 搞了个 QQ AI 机器人
java
Re_zero1 天前
以为用了 try-with-resources 就稳了?这三个底层漏洞让TCP双向通讯直接卡死
java·后端
SimonKing1 天前
Fiddler抓包完全指南:从安装配置到抓包,一文讲透
java·后端·程序员