Springboot的Test单元测试操作

Springboot的Test单元测试操作

简单总结需要操作的步骤

1,导入依赖
2,创建目录(目录和启动类的目录保持一致)
3,添加注解
4,写方法测试

1,导入依赖

java 复制代码
  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.7.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.1</version>
            <scope>test</scope>
        </dependency>

2,创建目录(目录和启动类的目录保持一致),并test目录绿色标记一下

3,添加注解
注意的是,这里的test的类路径import org.junit.Test;,idea自动导入可能是导入其他导致报错,这里注意一下就可以了

java 复制代码
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
public class PerdTest {
   @Test
    public void pageTest(){
    }

}
相关推荐
霸道流氓气质29 分钟前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
于先生吖1 小时前
SpringBoot对接大模型开发AI命理测算系统:八字排盘与AI解析接口源码全解
人工智能·spring boot·后端
Flittly1 小时前
【AgentScope Java新手村系列】(10)实战-多Agent天气助手
java·spring boot·spring
许彰午2 小时前
39_Java单元测试JUnit入门
java·junit·单元测试
星落zx4 小时前
Spring Boot 多模型集成:优雅调用全球主流大模型
人工智能·spring boot·chatgpt
一杯奶茶¥4 小时前
水果销售网站 CRM客户信息管理系统 超市管理系 酒店管理系统 健身房管理系统 在线音乐网站 校园招聘系统
java·vue.js·spring boot·mysql·spring·java项目
进阶的小名5 小时前
Spring Boot SSE + Nginx 配置:解决 EventSource 不实时返回、连接超时、流式响应被缓冲问题
spring boot·后端·nginx
我登哥MVP6 小时前
SpringCloud Alibaba 核心组件解析:服务链路追踪
java·spring boot·后端·spring·spring cloud·java-ee·maven
范什么特西6 小时前
Spring boot细节
java·spring boot·后端