Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

junit

junit5

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?

like image 682
ayaya Avatar asked Sep 21 '18 08:09

ayaya


People also ask

What is JUnit platform engine?

platform. engine. Public API for test engines. Provides the TestEngine interface, test discovery and execution reporting support.

What is org JUnit Jupiter API test?

JUnit Jupiter is the API for writing tests using JUnit version 5. JUnit 5 is the project name (and version) that includes the separation of concerns reflected in all three major modules: JUnit Jupiter, JUnit Platform, and JUnit Vintage.


1 Answers

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/

like image 176
Sormuras Avatar answered Oct 14 '22 21:10

Sormuras