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

28,327

Use version 5.3.x of the junit-jupiter-engine for now with 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>

Seems like you're struck by https://issues.apache.org/jira/browse/SUREFIRE-1564 which describes a known issue that Surefire 2.22.0 internally stays on version 1.2.0 for all junit-platfrom-xyz artifacts.

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/

Share:
28,327
ayaya
Author by

ayaya

Updated on July 21, 2022

Comments

  • ayaya
    ayaya almost 2 years

    I'm trying to use JUnit5.
    First, I added dependencies to maven project:

    <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?

  • Dmytro
    Dmytro over 4 years
    Downgrading from 5.5.2 to 5.3.2 fixed the issue. Thanks!
  • Sormuras
    Sormuras over 4 years
    Added above: "You should also give Surefire 3.x a try - afaik, it is compatible with all versions of JUnit: maven.apache.org/surefire/maven-surefire-plugin"