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

测试通过:

相关推荐
坐吃山猪1 天前
SpringBoot2.7集成Knife4j
springboot·knife4j
AI开源软件3 天前
SpringBoot信创项目怎么验收?从数据库迁移到交付证据
postgresql·springboot·达梦·opengauss·信创·企业管理系统
咖啡八杯3 天前
Redis 工具封装:RedisCache 对 Operations 体系的二次封装
java·数据库·redis·缓存·框架·springboot·若依
西凉的悲伤6 天前
Spring Boot 条件装配注解详解
java·springboot·1024程序员节·条件装配
xieliyu.7 天前
【JavaEE进阶】Spring Boot 日志:从 System.out 到 @Slf4j,6 个级别 + 4 类配置一篇讲透
java·spring boot·spring·java-ee·springboot·logback·slf4j
AI开源软件7 天前
SpringBoot + Vue3 人力资源管理系统推荐:组织、档案与移动办公
vue3·springboot·ruoyi·oa系统·移动办公·人力资源管理系统·hrm
AI源码8 天前
社区医院儿童健康信息管理系统
springboot
AI源码8 天前
社区论坛系统
springboot
AI源码9 天前
图书馆借阅管理系统
vue3·springboot
孤狼GPT9 天前
ChatGPT、Codex排查实录:Kafka消费者日志明明显示处理成功,为什么同一条消息还是被重复消费?
kafka·springboot·codex·chatgptplus·chatgptpro