SpringBoot ,想用单元测试功能,结果发现 @Runwith 不能实现,找不到。貌似与 SpringBoot 版本有关,像我这边spring-boot-starter-parent 的版本是 2.5.6,进入spring-boot-starter-test找依赖,只找到
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.7.2</version> <scope>compile</scope> </dependency>
经查才发现junit-jupiter 属于 Junit 5 。而之前的SpringBoot版本,像 2.1,依赖的是Junit 4。
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>compile</scope> </dependency>
如果想用单元测试,不用依赖 @RunWiht。直接使用@SpringBootTest就行。
我这也有完整代码。
想了解更多 Junit 5 用法,推荐 。
本文由老郭种树原创,转载请注明:https://guozh.net/springboot-runwith-not-found-junit/