Java 使用 JUnit5 时,我收到警告:“ClassNotFoundException: org.junit.platform.engine.support.filter.ExclusionReasonConsumingFilter”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52439379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When using JUnit5, I got a warning: "ClassNotFoundException: org.junit.platform.engine.support.filter.ExclusionReasonConsumingFilter"
提问by ayaya
I'm trying to use JUnit5.
First, I added dependencies to maven project:
我正在尝试使用 JUnit5。
首先,我向 Maven 项目添加了依赖项:
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Then, I created a test:
然后,我创建了一个测试:
package com.example.multicurrency;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class JunitTests {
@Test
void testAssertTrue() {
assertTrue(false);
}
}
After that, I run the test. The following is what I have got:
之后,我运行测试。以下是我所得到的:
org.junit.platform.launcher.core.DefaultLauncher handleThrowable
warning: TestEngine with ID 'junit-vintage' failed to discover tests
java.lang.NoClassDefFoundError: org/junit/platform/engine/support/filter/ExclusionReasonConsumingFilter
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.support.filter.ExclusionReasonConsumingFilter
org.opentest4j.AssertionFailedError:
Expected :<true>
Actual :<false>
The result was what I expected. But the warning confused me. What does the warning mean?
结果正如我所料。但警告让我感到困惑。警告是什么意思?
回答by Sormuras
Use version 5.3.x
of the junit-jupiter-engine
for now with Surefire 2.22.2
.
使用版本5.3.x
的junit-jupiter-engine
现在与神火2.22.2
。
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Seems like you're struck by https://issues.apache.org/jira/browse/SUREFIRE-1564which describes a known issue that Surefire 2.22.0
internally stays on version 1.2.0
for all junit-platfrom-xyz
artifacts.
似乎您对https://issues.apache.org/jira/browse/SUREFIRE-1564感到震惊,它描述了一个已知问题,即 Surefire2.22.0
内部保留1.2.0
所有junit-platfrom-xyz
工件的版本。
You should also give Surefire 3.x a try - afaik, it is compatible with all versions of JUnit: https://maven.apache.org/surefire/maven-surefire-plugin/
您还应该尝试 Surefire 3.xa - afaik,它与所有版本的 JUnit 兼容:https://maven.apache.org/surefire/maven-surefire-plugin/