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的更多相关文章

  1. unit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util

    在进行单元测试时,测试出现异常 Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform ...

  2. springboot单元测试 JUnit5

    JUnit5简介 Spring Boot 2.2.0 版本开始引入 JUnit 5 作为单元测试默认库 JUnit 5官方文档 作为最新版本的JUnit框架,JUnit5与之前版本的JUnit框架有很 ...

  3. Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V

    在学习CGlib动态代理时,遇到如下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.objectwe ...

  4. 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 ...

  5. 【原】tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig的解决

    现象: tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig() ...

  6. java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z 的解决

    jetty 9 嵌入式开发时,启动正常,但是页面一浏览就报错如下: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest ...

  7. java.lang.NoSuchMethodError:

    Servlet.service() for servlet [springMVC] in context with path [/mobile] threw exception [Handler pr ...

  8. 关于java.lang.NoSuchMethodError: android.widget.RelativeLayout.setBackground的解决办法

    今天用一个安卓4.0.4版本的手机测试手上的项目,发现logcat弹出这样一个提示“java.lang.NoSuchMethodError: android.widget.RelativeLayout ...

  9. 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 ...

随机推荐

  1. 记录java+testng运行selenium(三)---xml、ini、excel、日志等配置

    一: ini文件 ini目前只用处存储浏览类型及需要打开的url,ini文件放在configs文件夹下面. 读取ini代码如下: package toolskit.documents; import ...

  2. jwt的原理以及使用

    jwt原理(json web token) 我们之前是使用session实现登录,通过实际密码+盐组成字符串进行md5存入redis或者数据库中,输入的密码与实际校验通过,发送给客户端一个有效时间的t ...

  3. 小知识——c++关于指针的理解

    参考文章: 简介: 指针可以简化c++编程,在一些任务中没有指针是无法完成的(动态内存分配) 使用 & 可以获得变量在内存中的地址: eg: #include <iostream> ...

  4. subline html5的快捷键

    选择类 Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本. Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑.举个栗子:快速选中并更改所有相同的变量名.函数 ...

  5. 22 webpack结合Vue使用的总结

    总结梳理:webpack中如何使用vue: 1.安装vue的包:cnpm i vue -S 2.由于 在webpack中,推荐使用 .vue这个组件模板文件定义组件, 所以,需要安装 能解析这种文件的 ...

  6. MySQL 新建用户并赋予权限

    创建一个用户: create user 'oukele'@'%' identified by 'oukele'; 提示下面所列出的信息的话,得刷新一下权限表 The MySQL server is r ...

  7. BZOJ 3601 一个人的数论 (拉格朗日插值+莫比乌斯反演)

    题意 略 题解 orz Freopen的博客 CODE #pragma GCC optimize (3) #include <bits/stdc++.h> using namespace ...

  8. perfectpixel 加载PSD图到网页中和已经写好的网页进行对比

    perfectpixel  这是火狐的插件: 用途:加载设计图,和 已经编写好的网页进行对比,看是否完美还原. 谷歌也有类似的插件,但是无法下载.

  9. WebService操作

    webservice是一种服务器通信技术,封装了socket.

  10. Linux文件系统属性权限chattr与lsattr命令

    有时候你发现用root权限都不能修改某个文件,大部分原因是曾经用chattr命令锁定该文件了.chattr命令的作用很大,其中一些功能是由Linux内核版本来支持的,不过现在生产绝大部分跑的linux ...