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

相关推荐
砍材农夫5 分钟前
物联网实战|Spring Boot + Netty 搭建 MQTT 消息路由与流转层
java·spring boot·后端·物联网·spring
黄毛火烧雪下9 分钟前
Java 基础笔记:文件、递归与字符编码
java·开发语言·笔记
学计算机的计算基10 分钟前
链表算法上篇:LeetCode 206/234/141/142/160/21 题解与易错点
java·笔记·算法·链表
信也科技布道师12 分钟前
从Istio 503 NC 错误深入理解 Mesh 路由全链路原理
java·服务器·网络
swordbob16 分钟前
3 大 I/O 模型BIO / NIO / AIO
java·linux·spring
Pluto_CSND18 分钟前
Cron表达式使用说明
java
十五喵源码网18 分钟前
基于SpringBoot2+vue2的酒店客房管理系统
java·毕业设计·springboot·论文笔记
疯狂成瘾者32 分钟前
Java 常用工具包 java.util
java·开发语言·windows
ywl47081208737 分钟前
springSecurity+jwt,简单版demo
java·前端·servlet
lazy H1 小时前
Spring Boot 项目如何连接 Redis?新手入门配置和常见错误总结
ide·spring boot·redis·后端·学习·intellij-idea