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

测试通过:

相关推荐
CC大煊10 小时前
【java】Druid数据库连接池完整配置指南:从入门到生产环境优化
java·数据库·springboot
孔明兴汉16 小时前
springboot4 项目从零搭建
java·java-ee·springboot
大学生资源网19 小时前
基于springboot的农村综合风貌展示平台设计与实现(源码+文档)
java·数据库·spring boot·后端·毕业设计·源码·springboot
大学生资源网1 天前
java毕业设计之“知语”花卉销售网站的设计与实现源码(源代码+文档)
java·mysql·毕业设计·源码·springboot
千寻技术帮2 天前
10371_基于Springboot的书籍影视交流论坛
mysql·毕业设计·springboot·安装·书籍影视
Han.miracle3 天前
《Spring MVC 响应机制综合实践:页面、数据、JSON 与响应配置》
java·spring·springboot
热河暖男3 天前
使用 Flying-Saucer-Pdf + velocity 模板引擎生成 PDF(解决中文和图片问题)
java·pdf·html·springboot
阿拉斯攀登3 天前
电子签名:SpringBoot + 汉王 ESP560 的考核签名项目实施方案
springboot·canvas·电子签名·电子签·汉王
invicinble4 天前
对于认识IT系统的流量,服务器承载能力
springboot
wasteland~4 天前
Spring AI实战:SpringBoot项目结合Spring AI开发——Tool Calling(工具调用)详解与实战
springboot·工具调用·spring ai·tool calling