IntelliJ JUnit5 ClassNotFoundError

时间:2017-03-20 14:42:33

标签: java maven intellij-idea junit5

尝试运行我的TestFactory时出现此错误:

Mär 20, 2017 3:39:05 PM org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
INFORMATION: Discovered TestEngines with IDs: [junit-jupiter, junit-vintage]
Exception in thread "main" java.lang.NoClassDefFoundError: org/opentest4j/TestAbortedException
    at org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor.<clinit>(TestFactoryTestDescriptor.java:47)
    at org.junit.jupiter.engine.discovery.TestFactoryMethodResolver.resolveMethod(TestFactoryMethodResolver.java:56)
    at org.junit.jupiter.engine.discovery.TestMethodResolver.resolveElement(TestMethodResolver.java:63)
    at org.junit.jupiter.engine.discovery.JavaElementsResolver.tryToResolveWithResolver(JavaElementsResolver.java:164)
    at org.junit.jupiter.engine.discovery.JavaElementsResolver.lambda$resolve$8(JavaElementsResolver.java:155)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1548)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at org.junit.jupiter.engine.discovery.JavaElementsResolver.resolve(JavaElementsResolver.java:158)
    at org.junit.jupiter.engine.discovery.JavaElementsResolver.lambda$resolveForAllParents$4(JavaElementsResolver.java:128)
    at java.lang.Iterable.forEach(Iterable.java:75)
    at org.junit.jupiter.engine.discovery.JavaElementsResolver.resolveForAllParents(JavaElementsResolver.java:127)
    at org.junit.jupiter.engine.discovery.JavaElementsResolver.resolveMethod(JavaElementsResolver.java:65)
    at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.lambda$resolveSelectors$3(DiscoverySelectorResolver.java:63)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:62)
    at org.junit.jupiter.engine.JupiterTestEngine.resolveDiscoveryRequest(JupiterTestEngine.java:50)
    at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:43)
    at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:109)
    at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:79)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.opentest4j.TestAbortedException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 28 more

然而,当从命令行(mvn test)运行它时,它正在工作。

IDE:IntelliJ 2016.3.3 Java:1.8 Project SDK:Java 1.8

Libarier:

ant-1.8.2.jar
hamcrest-core-1.3.jar
junit-4.12.jar
junit-jupiter-api-5.0.0-M3.jar
junit-jupiter-engine-5.0.0-M3.jar
transform-executor-java-4.2.2-SNAPSHOT.jar
transform-util-java-4.6.1-SNAPSHOT.jar
xmlbeans-2.6.0.jar
xmlunit-1.5.jar

我不明白......

2 个答案:

答案 0 :(得分:4)

您必须将opentest4j-1.0.0-M1.jar添加到类路径

将以下依赖项添加到您的pom:

<!-- https://mvnrepository.com/artifact/org.opentest4j/opentest4j -->
<dependency>
    <groupId>org.opentest4j</groupId>
    <artifactId>opentest4j</artifactId>
    <version>1.0.0-M1</version>
    <scope>test</scope>
</dependency>

答案 1 :(得分:0)

JUnit罐子可能已经过时了。

  1. 删除项目依赖项中列出的内容
  2. @Test注释
  3. 上调用快速修复
  4. 选择Add JUnit5 to classpath
  5. 选择所需的Jar位置