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

测试通过:

相关推荐
九皇叔叔2 小时前
001-SpringSecurity-Demo 创建项目
java·springboot·springsecurity
她说..2 天前
Spring单例Bean线程安全问题 深度解析
java·后端·安全·spring·springboot
Flittly3 天前
【SpringAIAlibaba新手村系列】(5)Prompt 提示词基础与多种消息类型
java·笔记·spring·ai·springboot
冷血~多好4 天前
mysql实现主从复制以及springboot实现读写分离
java·数据库·mysql·springboot
aygh6 天前
互联网大厂Java面试场景:技术问答实录
mybatis·springboot·多线程·hashmap·java面试·arraylist·技术总结
Flittly7 天前
【SpringAIAlibaba新手村系列】(2)Ollama 本地大模型调用
java·ai·springboot
super_lzb7 天前
resources路径下的文件无法打入war包或jar包内
spring·springboot·springboot打包·war包·sources资源文件