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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:27:10  来源:igfitidea点击:

When using JUnit5, I got a warning: "ClassNotFoundException: org.junit.platform.engine.support.filter.ExclusionReasonConsumingFilter"

javajunitjunit5

提问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.xof the junit-jupiter-enginefor now with Surefire 2.22.2.

使用版本5.3.xjunit-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.0internally stays on version 1.2.0for all junit-platfrom-xyzartifacts.

似乎您对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/