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

测试通过:

相关推荐
suweijie76812 小时前
Nacos配置读取异常排查与解决指南
微服务·nacos·springboot·配置中心·问题排查
程序员老邢1 天前
【产品底稿 12】工程架构最终定型:完整模块拆分、分包规范、层级依赖与开发规约全清单
微服务·架构·springboot·多模块·技术债务
abcnull1 天前
Springboot+Vue2的Web项目小白入门Demo快速学习!
java·elementui·vue·maven·springboot·web·小白
qq_589568102 天前
springbootweb案例,出现访问 http://localhost:8080/list 一直处于浏览器运转阶段
java·网络协议·http·list·springboot
极光代码工作室2 天前
基于SpringBoot的图书管理系统
java·springboot·web开发·后端开发
小云小白4 天前
PostgreSQL JDBC 驱动长连接问题:无心跳导致的静默断连
postgresql·springboot·连接超时
程序员老邢5 天前
【产品底稿 11】架构规整收官:从混乱到清晰,工程结构、表命名、模块分层一次性定型
后端·架构·springboot·产品底稿·架构规整·模块分层·数据库规范
@yanyu6665 天前
登录注册功能-明文
vue.js·springboot
苏渡苇6 天前
DeepSeek V4 实战:自然语言生成 SQL + 智能优化引擎
ai·springboot·spring ai·deepseek·ai推理·deepseek v4·自然语言生成sql
玛卡巴卡ldf7 天前
【Springboot升级AI】(大模型部署)LangChain4j、会话记忆、隔离消失持久化问题、ollama、RAG知识库、Tools工具
java·开发语言·人工智能·spring boot·后端·springboot