Idea 运行测试NoSuchMethodError Junit5
1.背景
环境:
macOS 10.13.4
idea: 2016.3
springboot 版本: 2.2.2.RELEASE
pom依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
2.情况描述
之前用的是springboot1.5.9, 想用springboot2.x 写个demo看看,直接使用Idea新建了个springboot工程,然后一路next。
项目建完,写了个小case,想跑下test。 结果test类跑不起来,错误大概(没保存现场,这个是从网上找的类似的)如下:
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;
at org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.loadTestEngines(ServiceLoaderTestEngineRegistry.java:30)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
通过查询,得知原因是:IDEA版本过低不支持JUnit5引起的。我的是2016.3
然后junit包依赖如下:

网上的解决方案有
1). 导入Junit4的依赖,使用Junit4的测试包跑----> @SpringbootTest 还是会报错
2). Junit 依赖版本增加使用-M2
3). 剔除Junit5依赖。我的情况非此类,看我的依赖知道,我的是项目直接使用的Junit5。
4). 我甚至找到了一个跟我一模一样的,我自己的仍旧有问题。参考来源: http://leakfromjavaheap.blogspot.com/2016/12/playing-with-junit-5-and-intellij-idea.html
5). 升级IDEA
3.解决方案
采用升级IDEA完美解决,似乎是2017.3以后的版本就行,我直接升级到了2019.2。考虑到一劳永逸的问题,所以直接升级的。没有直接升级到2019.3的原因,是担心最新版不稳定。以上
4.后记
1. 关于升级:
升级2019.2或者2019.3后,升级后明显感觉卡顿了...(可能是我电脑硬件也该升级了吧)。通过尝试,发现2019.2编辑pom文件的时候,卡顿到怀疑人生,查询到可能是maven本地index的问题;2019.3,建议内存16G的升级,我的电脑老版本8G的,也不流畅;推荐升级2019.1, 毕竟稳定和流畅最重要。
2. 关于junit
网上很多人说springboot2.x默认使用junit4,实际尝试发现,其实是springboot2.1.x之前的版本,我的2.2.2.RELEASE,默认会用到junit5.
3. springboot和springcloud版本
一定要注意cloud和boot的版本,防止不兼容的坑。软件建议别上最新版,无论是学习还是work
Idea 运行测试NoSuchMethodError Junit5的更多相关文章
- unit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util
在进行单元测试时,测试出现异常 Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform ...
- springboot单元测试 JUnit5
JUnit5简介 Spring Boot 2.2.0 版本开始引入 JUnit 5 作为单元测试默认库 JUnit 5官方文档 作为最新版本的JUnit框架,JUnit5与之前版本的JUnit框架有很 ...
- Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
在学习CGlib动态代理时,遇到如下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.objectwe ...
- java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager
问题: 使用Springboot打包为war部署于Tomcat7中报错 java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringMa ...
- 【原】tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig的解决
现象: tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig() ...
- java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z 的解决
jetty 9 嵌入式开发时,启动正常,但是页面一浏览就报错如下: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest ...
- java.lang.NoSuchMethodError:
Servlet.service() for servlet [springMVC] in context with path [/mobile] threw exception [Handler pr ...
- 关于java.lang.NoSuchMethodError: android.widget.RelativeLayout.setBackground的解决办法
今天用一个安卓4.0.4版本的手机测试手上的项目,发现logcat弹出这样一个提示“java.lang.NoSuchMethodError: android.widget.RelativeLayout ...
- hive 使用where条件报错 java.lang.NoSuchMethodError: org.apache.hadoop.hive.ql.ppd.ExprWalkerInfo.getConvertedNode
hadoop 版本 2.6.0 hive版本 1.1.1 错误: java.lang.NoSuchMethodError: org.apache.hadoop.hive.ql.ppd.ExprWalk ...
随机推荐
- spice在桌面虚拟化中的应用系列之一(spice简介,性能优化等)
1.spice介绍 1.1 spice简介 spice是由Qumranet开发的开源网络协议,2008年红帽收购了Qumranet获得了这个协议.SPICE是红帽在虚拟化领域除了KVM的又一“新兴技术 ...
- C++——多维数组动态开辟与释放
前言 在讨论多维数组动态开辟与释放之前,先说说什么是二维数组静态开辟与释放. 形如这种就是静态开辟内存,事先画好了内存大小 #include<iostream> using namespa ...
- C++——new & delete
C++ new Complex类 String类 C++ delete Comlex类 String类 array new 一定要搭配array delete VC架构下new内存分配演绎 Linux ...
- 剖析gcc -v输出
分析gcc -v的详细信息的意义 首先我们需要清楚一点,我们并不能完全弄清楚gcc -v的所有信息,因为毕竟我们并不是GCC编译器集合的实现者,对于这些信息,他们才是最清楚的.由于我们不能将所有的信息 ...
- RT-Thread--内核移植
内核移植 内核移植就是指将 RT-Thread 内核在不同的芯片架构.不同的板卡上运行起来,能够具备线程管理和调度,内存管理,线程间同步和通信.定时器管理等功能.移植可分为 CPU 架构移植和 BSP ...
- Go语言实现简单的TCP、UDP链接
⼀.使用Golang创建⼀一个TCP连接 1.服务端处理理流程 a.监听端口 b.接受客户端的链接 c.创建Goroutine,处理这个链接(⼀个服务端要链接多个客户端,所以使用Gorouti ...
- linux网络编程之system v消息队列(二)
今天继续学习system v消息队列,主要是学习两个函数的使用,开始进入正题: 下面则开始用代码来使用一下该发送函数: 在运行之前,先查看一下1234消息队列是否已经创建: 用上次编写的查看消息队列状 ...
- python-selenium安装笔记
python-selenium操作火狐,谷歌,360,ie 亲测可用,windows环境 python3.6 由于python2到2020年不进行维护所有都用python3 selenium pip ...
- 预定义的基础类型转换,BitConverter,BitArray
一.BitConverter 将预定义的基础类型与字节数据进行互转 1.将值类型转成字节数组(Unicode):BitConverter.GetBytes() byte[] data = BitCon ...
- Hdu 4312-Meeting point-2——哈夫曼距离与切比雪夫距离
题意 从 $n$ 个点中选择一点,使得其他点到其的切比雪夫距离最小($0 < n \leq 1e5$). 分析 定理:$(x_1, y_1)$ 与 $(x_2, y_2)$ 的曼哈顿距离等于 $ ...