SpringBoot整合JUnit

一、SpringBoot整合JUnit

步骤1:添加整合junit起步依赖(可以直接勾选)

xml 复制代码
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

步骤2:编写测试类,注入测试类

java 复制代码
@SpringBootTest
class SpringbootApplicationTests {
    @Autowired
    private BookService bookService;

    @Test
    public void testSave() {
        bookService.save();
    }
}

测试通过:

相关推荐
她说..3 天前
MySQL 与 Java 的 JSON 数据处理
java·mysql·json·springboot
Mr.Java.4 天前
本地测试全绿,上线 SQL 报错?Spring Boot 容器级 DT 测试实战指南(附Skills)
java·测试用例·springboot·testcontainers·dt·java测试skills·dt测试
苏渡苇4 天前
Spring Insight 里上报 Span 为什么用 JDK HttpClient 而不是 RestTemplate
java·后端·spring·spring cloud·springboot·性能监控
欢醉4 天前
生产复盘:请求报413 Request Entity Too Large问题分享
springboot·springcloud
慧都小项6 天前
MyEclipse 2026:当 Agent、MCP 与 Java 26 进入 Eclipse 工作流
java·eclipse·springboot·copilot·myeclipse
冬栈程序设计7 天前
Springboot宿舍管理系统【670099】 -附源码(开箱即用)
java·毕业设计·springboot·课程设计·程序设计·大作业
苏生Susheng8 天前
【软件实施】Linux企业运维常用命令手册
java·linux·运维·服务器·springboot·springcloud·软件实施
武哥聊编程8 天前
【AI实战项目】基于LangChain4j+Springboot+Vue+RAG+PGVector的AI智能客服与工单处理系统
springboot·rag·pgvector·langchain4j
小宇宙清歡渡8 天前
Java Stream 流全面实战指南(Spring Boot 3 + JDK 17)
java·springboot·stream流
小宇宙清歡渡10 天前
SpringBoot JDK17 线程池的使用
springboot·线程池·jdk17