【发布时间】:2020-01-18 12:32:19
【问题描述】:
我正在尝试运行基本的 JUnit5 程序。将 Eclipse Oxygen.3a(4.7.3a) 与 OpenJdk9 一起使用。出现如下错误 -
java.lang.NoClassDefFoundError: org/junit/platform/launcher/core/LauncherFactory
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:31)
.
.
.
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.core.LauncherFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
我看过这个 - Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory 但是由于我的 IDE 是最新的,所以不确定我现在缺少什么。
我的代码如下:
主类
package io.javabrains;
public class MathUtils {
public int add(int a, int b) { return a + b;}
}
测试类
package io.javabrains;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class MathUtilsTest {
@Test
void test() {
System.out.println("This test ran successfully");
//fail("Not yet implemented");
}
}
POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.javabrains</groupId>
<artifactId>junit-5-basics</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>junit-5-basics</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.jupiter.version>5.4.0</junit.jupiter.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
【问题讨论】:
-
老实说,您的 IDE 不是最新的,因为它是 4.7 版,而最近的版本是 4.12 或 2019-09 ...除此之外,您是否检查过构建是否在普通命令上工作行吗?