软件编程
位置:首页>> 软件编程>> java编程>> spring boot org.junit.jupiter.api不存在的解决

spring boot org.junit.jupiter.api不存在的解决

作者:紫陌幽茗  发布时间:2023-07-11 18:34:16 

标签:springboot,org.junit.jupiter.api,不存在

org.junit.jupiter.api不存在

解决方案

spring boot2.2之后和之前的测试类编写方法不一致

修改为:


// A code block
import org.junit.Test;import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
class CloudstudyApplicationTests {
   @Test
   void contextLoads() {
   }
}

新建Springboot项目默认test包下的测试类报错缺少org.junit.jupiter.api

在springboot项目中碰到一个问题,记录一下:新建了一个普通的Maven项目A,其pom.xml继承parent为:


<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.0.3.RELEASE</version>
   <relativePath/>
</parent>

然后在其下新建ModuleB(Springboot项目),奇怪的是新建的Module中的依赖导入后,编译报错(其实使用Maven的install也会报错)

报错如下

spring boot org.junit.jupiter.api不存在的解决

spring boot org.junit.jupiter.api不存在的解决

显示org.junit.jupiter.api不存在,很明显是缺少对应的依赖。

但是为什么会缺少junit的依赖呢,之前单独建springboot项目时都没有这个问题啊,虽然加上对应的依赖可以解决问题,但还是想找到原因。。。网上找了好久,总算找到满意的答案了。

原因分析

spring boot 2.2 之前使用的是 Junit4 而后续的使用的是Junit5,导致缺少包。我新建的父项目A是用的2.0.3版本的,而后面建的ModuleB选的是2.2.4版本。

解决方案

知道原因解决方法就好说了,升级A的parent为2.2以上版本,test也改为对应的版本。也可直接改ModuleB的test版本为parent对应的2.2以上的版本。都能解决,我当时是简单粗暴的直接加上junit5的依赖。。。如下,,

spring boot org.junit.jupiter.api不存在的解决

来源:https://blog.csdn.net/weixin_43165512/article/details/105147714

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com