IntelliJ IDEA 2017.1.5의 동일한 프로젝트에서 JUnit4 및 JUnit5 테스트를 사용하려고합니다. 지금까지 모든 테스트는 JUnit4를 기반으로했습니다. 나는 추가 jupiter
, platform
그리고 vintage
내 pom.xml 파일에 종속합니다 (를 포함 junit-platform-surefire-provider
하고 junit-vintage-engine
확실한 플러그인). 이제 JUnit4에 대한 예제 테스트도 JUnit 5에 대한 테스트도 실행되지 않습니다.
대신 다음과 같은 오류가 발생합니다.
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)
Process finished with exit code 1
Empty test suite.
가능한 한 JUnit 5 사용자 가이드 의 조언을 따르려고했지만 뭔가 놓친 것 같습니다. 두 테스트를 모두 제대로 실행하려면 어떻게해야합니까? (물론 내 모든 기존 테스트)
package com.glaed.util;
import org.junit.Test;
public class JUnit4Test {
@Test
public void helloJUnit4Test() {
System.out.println("Hello JUnit4!");
}
}
package com.glaed.util;
import org.junit.jupiter.api.Test;
class JUnit5Test {
@Test
void helloJU5test() {
System.out.println("Hello JUnit5!");
}
}
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testSourceDirectory>src/test</testSourceDirectory>
<excludes>
<exclude>**/*WebappTest.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M5</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M5</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>4.12.0-M5</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<!-- JUNIT5 & JUPITER -->
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>4.12.0-M5</version>
<scope>test</scope>
</dependency>
<!-- JUnit 4 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
다음 버전을 사용하십시오 junit-jupiter-api
.
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M4</version>
<scope>test</scope>
</dependency>
또한 5.0.0-M4
모든 junit-jupiter
종속성 에 대한 버전 을 사용하십시오 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다