Junitテストで異常が発生:Exception in thread"main"java.lang.NoSuchMethodError: org.junit.platform.commons.util.
6325 ワード
ユニットテスト中、テストに異常が発生しました
問題の原因エラーは
このモジュールはJUnit 5専用に設計されているため、https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
ソリューション
1、削除
原文(英語)住所: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)
pom.xml
依存度は次のとおりです.<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.12version>
dependency>
<dependency>
<groupId>org.junit.jupitergroupId>
<artifactId>junit-jupiter-apiartifactId>
<version>RELEASEversion>
dependency>
dependencies>
問題の原因エラーは
pom.xml
の依存で、コンソールの出力をよく見ると、IntelliJ IDEAがJUnit 5を使用して私のテスト例を実行しようとしていることがわかります.at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
pom.xml
を通して、私はJUnit 4を使いたいことを発見しました.12テスト例を実行し、pom.xml
を見て、junit-jupiter-apiという依存がこのエラーを引き起こすことを発見しました.<dependency>
<groupId>org.junit.jupitergroupId>
<artifactId>junit-jupiter-apiartifactId>
<version>RELEASEversion>
dependency>
このモジュールはJUnit 5専用に設計されているため、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