Junit测试出现异常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.
2017-12-06 12:18
671 查看
在进行单元测试时,测试出现异常
2
3
4
5
6
7
2
3
4
5
6
7
8
9
10
11
12
问题原因
错误就在
通过
2
3
4
5
因为此模块专为JUnit5而设计 -https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
解决方案
1、删除
2、Reimport All Maven Project
原文(英文)地址:https://stackoverflow.com/questions/45004453/cannot-run-tests-intellij-spring-project-error-java-lang-nosuchmethoderror
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)1
2
3
4
5
6
7
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>1
2
3
4
5
6
7
8
9
10
11
12
问题原因
错误就在
pom.xml的依赖中,仔细查看控制台输出你会发现IntelliJ IDEA正在尝试使用JUnit5运行我的测试用例。
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)1
通过
pom.xml发现,我希望使用JUnit4.12运行测试用例,我们查看
pom.xml发现junit-jupiter-api这个依赖会导致这个错误。
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>RELEASE</version> </dependency>1
2
3
4
5
因为此模块专为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
相关文章推荐
- unit测试出现异常: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.NoClassDefFoundError: org/apache/commons/lang/exception/Nestabl
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
- 遍历集合时出现的异常Exception in thread "main" java.util.ConcurrentModificationException
- myeclipse中发送邮件出现Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
- javamail异常发送邮件出现Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/ut
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/yarn/util/Apps Hadoop2.6.0编程问题与解决
- Andriod测试错误 Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter 解决
- 安装maven出现错误:Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/
- 遍历集合时出现的异常Exception in thread "main" java.util.ConcurrentModificationException
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
- Spring Exception:Exception in thread "main" java.lang.NoClassDefFoundError:org/apache/commons/loggin
- Exceptioninthread"main"java.lang.NoClassDefFoundError:org/apache/hadoop/util/ProgramDriver
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
- hadoop解决Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/yarn/util/Apps
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory