I am trying to use JUnit4 and JUnit5 tests in the same project in IntelliJ IDEA 2017.1.5. So far, all tests have been based on JUnit4. I added the jupiter , platform and vintage dependencies to my pom.xml (including junit-platform-surefire-provider and junit-vintage-engine for the surefire plugin). Now not a single test example is run for JUnit4, not one for JUnit 5.
Instead, the following error occurs:
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.
I tried as closely as possible to follow the recommendations of the JUnit 5 User Guide , but I probably missed something. How can I make both tests work fine? (and all my existing tests, of course)
JUnit 4 Testing Class
package com.glaed.util; import org.junit.Test; public class JUnit4Test { @Test public void helloJUnit4Test() { System.out.println("Hello JUnit4!"); } }
JUnit 5 Testing Class
package com.glaed.util; import org.junit.jupiter.api.Test; class JUnit5Test { @Test void helloJU5test() { System.out.println("Hello JUnit5!"); } }
pom.xml (relevant sections)
<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> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.0.0-M5</version> <scope>test</scope> </dependency> <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> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies>
intellij-idea maven junit junit4 junit5
glaed
source share