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(){
    }

}
相关推荐
java水泥工24 分钟前
旅游管理系统|基于SpringBoot和Vue的旅游管理系统(源码+数据库+文档)
spring boot·vue·计算机毕业设计·java毕业设计·旅游管理系统
计算机学长felix1 小时前
基于SpringBoot的“基于数据安全的旅游民宿租赁系统”的设计与实现(源码+数据库+文档+PPT)
数据库·spring boot·旅游
Q_Q51100828511 小时前
python+uniapp基于微信小程序的旅游信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js
Q_Q51100828512 小时前
python基于web的汽车班车车票管理系统/火车票预订系统/高铁预定系统 可在线选座
spring boot·python·django·flask·node.js·汽车·php
DokiDoki之父13 小时前
MyBatis—增删查改操作
java·spring boot·mybatis
摇滚侠14 小时前
Spring Boot 项目, idea 控制台日志设置彩色
java·spring boot·intellij-idea
Code blocks16 小时前
GB28181视频服务wvp部署(一)
java·spring boot·后端
我命由我1234516 小时前
Spring Boot - Spring Boot 静态资源延迟响应(使用拦截器、使用过滤器、使用 ResourceResolver)
java·spring boot·后端·spring·java-ee·intellij-idea·intellij idea
xiangzhihong818 小时前
Spring Boot集成SSE实现AI对话的流式响应
人工智能·spring boot