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

测试通过:

相关推荐
Flittly1 天前
【SpringSecurity新手村系列】(3)自定义登录页与表单认证
java·笔记·安全·spring·springboot
Flittly2 天前
【SpringSecurity新手村系列】(2)整合 MyBatis 实现数据库认证
java·安全·spring·springboot·安全架构
极光代码工作室2 天前
基于SpringBoot的在线考试系统
java·springboot·web开发·后端开发
YDS8293 天前
大营销平台 —— 抽奖规则决策树
java·springboot·ddd
码农张34 天前
自定义跨字段校验必填注解
springboot
格鸰爱童话4 天前
向AI学习项目技能(七)
学习·springboot
代码漫谈4 天前
微服务 vs 单体架构:架构选型、实战拆解与决策指南
java·微服务·springboot·springcloud
文慧的科技江湖4 天前
光储充一体化系统落地 PRD 全功能清单 - 慧知开源充电桩平台
java·mysql·开源·springboot·慧知开源充电桩平台·充电重复订单解决方案源码
Flittly5 天前
【SpringAIAlibaba新手村系列】(16)调用百度 MCP 服务
java·笔记·spring·ai·springboot
MegaDataFlowers6 天前
yaml配置注入
springboot