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

相关推荐
程序员晓琪7 分钟前
约定大于配置:基于 Java 包名自动生成 API 版本路由的最佳实践
java·spring boot·后端
Flittly13 分钟前
【AgentScope Java新手村系列】(11)中断与恢复
java·spring boot·spring
众少成多积小致巨39 分钟前
JNI (Java Native Interface) 技术手册中文参考指南
android·java·c++
东坡白菜1 小时前
破局全栈:前端开发的Java入门实战记录—JPA(2)
java·后端
SimonKing7 小时前
艹,维护AI写的代码,我心态崩了......
java·后端·程序员
用户298698530147 小时前
Java Word 文档样式进阶:段落与文本背景色设置完全指南
java·后端
小bo波1 天前
从"任意文件复制"深挖Java I/O:字符流与字节流的本质抉择
java·nio·io流·后端开发·文件复制
用户3521802454751 天前
🎆从 Prompt 到 Skill:让 Spring AI Agent 学会"装新技能"
人工智能·spring boot·ai编程
nanxun8862 天前
记一次诡异的 Docker 容器"串包"故障排查
java
用户1563068103512 天前
Day01 | Java 基础(Java SE)
java