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 天前
mysql实现主从复制以及springboot实现读写分离
java·数据库·mysql·springboot
aygh3 天前
互联网大厂Java面试场景:技术问答实录
mybatis·springboot·多线程·hashmap·java面试·arraylist·技术总结
Flittly3 天前
【SpringAIAlibaba新手村系列】(2)Ollama 本地大模型调用
java·ai·springboot
super_lzb4 天前
resources路径下的文件无法打入war包或jar包内
spring·springboot·springboot打包·war包·sources资源文件
哆啦A梦15884 天前
统一返回包装类 Result和异常处理
java·前端·后端·springboot
庄周的大鱼5 天前
分析@TransactionalEventListener注解失效
java·spring·springboot·事务监听器·spring 事件机制·事务注解失效解决
没有bug.的程序员6 天前
S 级 SaaS 平台的物理雪崩:Spring Cloud Gateway 多租户动态路由与 UserID 极限分片
java·gateway·springboot·saas·springcloud·多租户、·userid
堕落年代6 天前
破若依Springboot3连接Redisson
springboot