Spring Boot 整合 Junit 单元测试
SpringBoot2.x 使用 Junit5 作为测试平台

修改 POM 文件添加 Test 启动器
一般用官网创建或者是IDEA工具创建的都自带了
注意一下如果配置了这个,就不能用5一下的junit了

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!--junit-vintage-engine 提供了 Junit3 与 Junit4 的运行平台-->
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
测试代码
加两个注解就可以进行测试了


本文详细介绍如何在SpringBoot 2.x应用中使用Junit5进行单元测试,包括添加Test启动器的配置,以及如何通过简单注解进行测试。重点在于兼容性和测试代码示例。
2882

被折叠的 条评论
为什么被折叠?



