Skip to content

Junit 5/Surefire issue #835

Open
Open
@NicoLaval

Description

@NicoLaval

Affected version

3.5.3

Bug description

Hi,

I'm using Junit Jupiter 5 and surefire to run my Java tests (Java 17).
I didn't succeed to inject displayName in my surefire report:

  <testcase name="dynamicTestsFromCollection()[1]" classname="my_package" time="0.0"/>
  <testcase name="dynamicTestsFromCollection()[2]" classname="my_package" time="0.0"/>
  <testcase name="dynamicTestsFromCollection()[3]" classname="my_package" time="0.0"/>

Here is my Java test class:

class MyTest {

    @TestFactory
    Collection<DynamicTest> dynamicTestsFromCollection() {
        return Arrays.asList(
                DynamicTest.dynamicTest("1st dynamic test", () -> assertTrue(isEven(2))),
                DynamicTest.dynamicTest("2nd dynamic test", () -> assertTrue(isEven(4))),
                DynamicTest.dynamicTest("3rd dynamic test", () -> assertFalse(isEven(3)))
        );
    }

    private boolean isEven(int number) {
        return number % 2 == 0;
    }
}

Here is my configuration:

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <scope>test</scope>
        </dependency>
        ...
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.12.2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.5.3</version>
                <configuration>
                    <argLine>--add-exports java.base/sun.nio.ch=ALL-UNNAMED</argLine>
                    <useModulePath>false</useModulePath> <!-- mandatory for JUnit 5 -->
                    <systemProperties>
                        <property>
                            <name>junit.jupiter.displayname.generator.default</name>
                            <value>org.junit.jupiter.api.DisplayNameGenerator$Standard</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>
            ...
        </plugins>
    </build>

Also reported in junit5 discutions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions