簡體   English   中英

使用 JUnit5 時,我收到警告:“ClassNotFoundException: org.junit.platform.engine.support.filter.ExclusionReasonConsumingFilter”

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

我正在嘗試使用 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>

然后,我創建了一個測試:

package com.example.multicurrency;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class JunitTests {
    @Test
    void testAssertTrue() {
        assertTrue(false);
    }
}

之后,我運行測試。 以下是我得到的:

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>

結果如我所料。 但是這個警告讓我感到困惑。 警告是什么意思?

現在將junit-jupiter-engine 5.3.x版與 Surefire 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>

似乎您對https://issues.apache.org/jira/browse/SUREFIRE-1564感到震驚,它描述了一個已知問題,即 Surefire 2.22.0內部保留所有junit-platfrom-xyz工件的版本1.2.0

您還應該嘗試 Surefire 3.xa - afaik,它與所有版本的 JUnit 兼容: https ://maven.apache.org/surefire/maven-surefire-plugin/

我通過更新2017.2到2018.2.4的intellij想法解決了這個問題。 但我還沒弄清楚是什么導致它以及為什么它解決了。

感謝您的友好答案和評論。

  1. 添加 JUNIT5 依賴項時,它會自動包含“junit-platform-engine”和“junit-jupiter-api”。 您可以在“Pom.xml”的依賴層次結構中檢查這一點。 因此您可以刪除與 JUNIT5 一起添加的其他依賴項。 僅依賴 JUNIT5 就足夠了。
  2. 還要確保沒有對 JUNIT4 依賴項的引用。 如果您嘗試混合使用 JUNIT 和 JUNT5,則可能會出現此類警告,因為您在欺騙 JVM。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM