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

相关推荐
是小蟹呀^1 小时前
Spring Security + JWT 面试题整理
java·jwt·springsecurity
spencer_tseng3 小时前
Redis + Nacos.bat
java·windows·dos
霸道流氓气质3 小时前
SpringBoot中通用工具类库(Utils)封装与使用实践
spring boot·后端·python
troyzhxu4 小时前
列表查询的 GraphQL —— 一行代码终结你的 if-else 地狱!
java·springboot·graphql
孫治AllenSun4 小时前
【DataX】生产环境搭建DataX集群案例
java·开发语言·jvm
好好沉淀5 小时前
@NotBlank(message = “{xxx}“) 注解中花括号的含义
java
fīɡЙtīиɡ ℡5 小时前
内存泄漏产生的原因
java·spring·servlet
hkj88085 小时前
Ubuntu 切换java版本
java·linux·ubuntu
码智社7 小时前
Java实现RSA密钥生成、加密解密、加签验签
java