gpt4 book ai didi

java - 线程 "main"java.lang.NoClassDefFoundError : org/junit/platform/commons/util/ClassNamePatternFilterUtils 中出现异常

转载 作者:行者123 更新时间:2023-12-01 16:44:52 25 4
gpt4 key购买 nike

我想配置 Maven 使用这些依赖项运行 Junit 5 测试:

        <dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.7.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.7.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.3.3</version>
<scope>test</scope>
</dependency>

但我得到了异常(exception):

"C:\Program Files\Java\jdk-14\bin\java.exe"
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/commons/util/ClassNamePatternFilterUtils
at org.junit.platform.launcher.core.LauncherFactory.loadAndFilterTestExecutionListeners(LauncherFactory.java:113)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:99)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:72)
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:46)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:31)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.util.ClassNamePatternFilterUtils
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)

你知道我该如何解决这个问题吗?

最佳答案

添加以下代码或 Maven 等效代码:

testRuntimeOnly "org.junit.platform:junit-platform-commons:1.7.0"

说明:
ClassNamePatternFilterUtils 属于 platfrom-commons ,它是传递依赖。该类在1.7.0版本中引入。因此,需要显式添加依赖项。

关于java - 线程 "main"java.lang.NoClassDefFoundError : org/junit/platform/commons/util/ClassNamePatternFilterUtils 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61801256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com