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

测试通过:

相关推荐
洛阳泰山8 小时前
Maxkb4j集成sqlbot MCP实现企业智能问数智能体
java·ai·springboot·agent·智能问数
zc.z1 天前
基于 LangChain4j 的 RAG 工作流智能体实战
langchain·大模型·springboot·rag智能体
suweijie7681 天前
Nacos配置读取异常排查与解决指南
微服务·nacos·springboot·配置中心·问题排查
程序员老邢2 天前
【产品底稿 12】工程架构最终定型:完整模块拆分、分包规范、层级依赖与开发规约全清单
微服务·架构·springboot·多模块·技术债务
abcnull2 天前
Springboot+Vue2的Web项目小白入门Demo快速学习!
java·elementui·vue·maven·springboot·web·小白
qq_589568103 天前
springbootweb案例,出现访问 http://localhost:8080/list 一直处于浏览器运转阶段
java·网络协议·http·list·springboot
极光代码工作室3 天前
基于SpringBoot的图书管理系统
java·springboot·web开发·后端开发
小云小白5 天前
PostgreSQL JDBC 驱动长连接问题:无心跳导致的静默断连
postgresql·springboot·连接超时
程序员老邢6 天前
【产品底稿 11】架构规整收官:从混乱到清晰,工程结构、表命名、模块分层一次性定型
后端·架构·springboot·产品底稿·架构规整·模块分层·数据库规范
@yanyu6666 天前
登录注册功能-明文
vue.js·springboot