Junit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.
来源:互联网 发布:网络加密方式有哪些 编辑:程序博客网 时间:2024/06/07 03:49
在进行单元测试时,测试出现异常
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)
pom.xml
依赖如下
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>RELEASE</version> </dependency></dependencies>
问题原因
错误就在pom.xml
的依赖中,仔细查看控制台输出你会发现IntelliJ IDEA正在尝试使用JUnit5运行我的测试用例。
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
通过pom.xml
发现,我希望使用JUnit4.12运行测试用例,我们查看pom.xml
发现junit-jupiter-api这个依赖会导致这个错误。
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>RELEASE</version></dependency>
因为此模块专为JUnit5而设计 -https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
解决方案
1、删除
pom.xml
中org.junit.jupiter
依赖
2、Reimport All Maven Project
原文(英文)地址:https://stackoverflow.com/questions/45004453/cannot-run-tests-intellij-spring-project-error-java-lang-nosuchmethoderror
阅读全文
2 0
- Junit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.
- Junit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.
- Junit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.runner.Description.cre
- Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.digester.Digester.parse(L
- 使用PDFBox,出现Exception in thread "main" java.lang.NoSuchMethodError: org.fontbox.cmap.CMapParser.parse
- Andriod测试错误 Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter 解决
- org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;
- Exception in thread "main" java.lang.NoSuchMethodError
- org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()
- org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/Nestabl
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/Nestabl
- java中出现java.lang.NoSuchMethodError: main,Exception in thread "main"
- scala出现异常:Exception in thread "main" java.lang.StackOverflowError
- Exception in thread "main" java.lang.NoSuchMethodError: main
- Exception in thread "main" java.lang.NoSuchMethodError: main
- (1)Exception in thread "main" java.lang.NoSuchMethodError:main
- Spring Exception:Exception in thread "main" java.lang.NoClassDefFoundError:org/apache/commons/loggin
- Hadoop好友推荐系统-数据库过滤数据到HDFS
- jq 属性选择器动态属性值 和v-for 中嵌套v-for
- 达人篇:2)质量的小误会
- redis cli命令
- 如何在阿里云上安装JDK、Tomcat以及其配置过程
- Junit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.
- 命令行操作oracle,显示英文而不是中文
- MySQL优化(连接优化和缓存优化)
- Android Framework启动流程分析
- 剑指offer面试题42_1翻转单词顺序(java实现)
- Android 文件系统之 superblock/Inode/Inode table
- 91. Decode Ways
- webpack构建React应用五:使用webpack Loaders 模块加载器(三)
- OACLE 个人常用函数总结