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.举例

相关推荐
SL_staff4 分钟前
制造订单交付闭环实践:用跨部门计划模板解决缺料-停机-返工三角死循环
java·开源·产品
device_Any7 分钟前
接口文档写着三个字段,接口返回了五个
android·java·linux
Small-Young8 分钟前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南
数据库·spring boot·mysql·postgresql·乐观锁·并发控制
Wang's Blog13 分钟前
Java 项目实战: 交友项目 - 小视频模块实战:访客记录、FastDFS 存储与 SpringCache 缓存
java·缓存·交友
香蕉大香蕉(06敬畏市场)23 分钟前
MySQL 单点详解(09)
java·数据库·mysql·面试·八股·大厂实习
吹什么轩1 小时前
constexpr 完全指南:从 const 的两种含义,到编译期计算的四次演进
java·前端·javascript
她的男孩1 小时前
租户 A 的验证码,却用了租户 B 的 AccessKey:Forge Admin 修跨租户短信串发
java·spring boot·saas
LabVIEW开发1 小时前
LabVIEW 局部变量与数据流:这道 CLAD 题为什么答案是 Undefined
java·开发语言·labview
文丑颜不良啊1 小时前
LeetCode1721~1740题目解析
java·leetcode
wangbing11251 小时前
监控网页项目常用英文缩写
java