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

相关推荐
dovens6 分钟前
SpringBoot集成MQTT客户端
java·spring boot·后端
❀͜͡傀儡师11 分钟前
Spring Boot 集成 RocksDB 实战:打造高性能 KV 存储加速层
java·spring boot·后端·rocksdb
BENA ceic27 分钟前
Spring 的三种注入方式?
java·数据库·spring
小雅痞30 分钟前
[Java][Leetcode middle] 209. 长度最小的子数组
java·算法·leetcode
二哈赛车手41 分钟前
新人笔记---项目中简易版的RAG检索后评测指标(@Recall ,Mrr..)实现
java·开发语言·笔记·spring·ai
做时间的朋友。42 分钟前
精准核酸检测
java·数据结构·算法
许彰午1 小时前
CacheSQL(五):桥接篇
java·数据库·缓存·系统架构
NaMM CHIN1 小时前
Spring Boot + Spring AI快速体验
人工智能·spring boot·spring
ATCH IERV1 小时前
Java实战:Spring Boot application.yml配置文件详解
java·网络·spring boot
咸鱼2.01 小时前
【java入门到放弃】XXL-JOB
java