首页 > 编程语言 > 详细

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

时间:2017-09-14 14:43:14      阅读:1502      评论:0      收藏:0      [点我收藏+]

在进行单元测试时,测试出现异常

Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;

错误就在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.xmlorg.junit.jupiter依赖 
2、Reimport All Maven Project

原文(英文)地址:https://stackoverflow.com/questions/45004453/cannot-run-tests-intellij-spring-project-error-java-lang-nosuchmethoderror

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

原文:http://www.cnblogs.com/javaxiaodoufu/p/7520210.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!