Junit測試出現異常:Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.


在進行單元測試時,測試出現異常

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM