Springboot框架—单元测试操作

Springboot单元测试的操作步骤:

1.添加依赖spring-boot-starter-test

在pom.xml中添加依赖spring-boot-starter-test

2.在src/test/java下新建java class

3.单元测试入口代码结构

java 复制代码
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.boot.test.context.SpringBootTest;



@RunWith(SpringRunner.class)
@SpringBootTest(classes =Application.class )  //指定启动类
public class MyController {

    @Test
    public void test()  {
    }
}

4.执行

run 单元测试文件

6.执行结果

7.举例

相关推荐
Java面试题总结6 小时前
FVG3 构建系统 MinGW 配置问题排查文档
java
乐之者v7 小时前
游标分批查询,提高查询性能
java
城管不管7 小时前
嵌入模型Embedding Model
java·开发语言·python·embedding·嵌入模型
斯维赤7 小时前
每天学习一个小算法:选择排序
java·学习·算法
book123_0_997 小时前
Spring Boot 条件注解:@ConditionalOnProperty 完全解析
java·spring boot·后端
NCIN EXPE7 小时前
使用Springboot + netty 打造聊天服务(一)
java·spring boot·后端
爱学习的小囧7 小时前
ESXi性能历史怎么监控?2种方法,图形化+命令行全覆盖
java·linux·运维·服务器·网络·esxi·esxi8.0
逻辑驱动的ken7 小时前
Java高频面试考点场景题11
java·深度学习·面试·职场和发展·高效学习
MXN_小南学前端7 小时前
Vue3 + Spring Boot 工单系统实战:用户反馈和客服处理的完整闭环(提供gitHub仓库地址)
前端·javascript·spring boot·后端·开源·github
学习3人组7 小时前
面向对象编程:反射(Reflection)原理与应用详解
java