spring boot org.junit.jupiter.api不存在的解决
作者:紫陌幽茗 时间:2023-07-11 18:34:16
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也会报错)
报错如下
显示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的依赖。。。如下,,
来源:https://blog.csdn.net/weixin_43165512/article/details/105147714
标签:springboot,org.junit.jupiter.api,不存在
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android TextView中文字通过SpannableString设置属性用法示例
2023-07-26 07:11:51
![](https://img.aspxhome.com/file/2023/8/84748_0s.jpg)
Java编程用两个栈实现队列代码分享
2023-03-22 01:05:05
Java 单例模式的实现资料整理
2022-05-29 21:27:33
Java中的this、package、import示例详解
2021-06-10 10:37:50
![](https://img.aspxhome.com/file/2023/6/106166_0s.png)
Java Bean 作用域及它的几种类型介绍
2022-12-02 20:39:42
![](https://img.aspxhome.com/file/2023/9/75479_0s.png)
C#中的HttpWebRequest类用法详解
2022-11-07 11:41:17
Java套接字(Socket)网络编程入门
2022-09-22 16:19:56
Java生产1-100的随机数简单实例(分享)
2021-08-15 02:52:28
Java实现的上传并压缩图片功能【可等比例压缩或原尺寸压缩】
2023-03-17 11:09:11
![](https://img.aspxhome.com/file/2023/5/80855_0s.jpg)
java线程池对象ThreadPoolExecutor的深入讲解
2023-05-15 06:49:51
![](https://img.aspxhome.com/file/2023/7/64027_0s.png)
Java实现快速排序算法的完整示例
2022-10-15 11:57:40
![](https://img.aspxhome.com/file/2023/2/68752_0s.gif)
Spring框架开发scope作用域分析总结
2023-05-04 14:43:44
![](https://img.aspxhome.com/file/2023/8/122248_0s.png)
tcp、udp、ip协议分析_动力节点Java学院整理
2023-05-17 18:00:17
![](https://img.aspxhome.com/file/2023/3/116543_0s.png)
基于Java实现获取本地IP地址和主机名
2023-03-19 04:03:55
Android中WebView图片实现自适应的方法
2021-11-15 06:37:32
vista和win7在windows服务中交互桌面权限问题解决方法:穿透Session 0 隔离
2021-06-16 04:05:47
![](https://img.aspxhome.com/file/2023/0/72480_0s.png)
Android实现腾讯新闻的新闻类别导航效果
2023-07-29 04:17:46
![](https://img.aspxhome.com/file/2023/3/85973_0s.png)
mybatis-plus的批量新增/批量更新以及问题
2022-10-28 04:44:16
![](https://img.aspxhome.com/file/2023/2/67972_0s.png)
C# WinForm实现自动更新程序之客户端的示例代码
2022-03-28 03:26:24
![](https://img.aspxhome.com/file/2023/0/89750_0s.png)
Android编程实现给Button添加图片和文字的方法
2021-11-27 21:30:20