13

JUnit5 tests results are not showing the specified @DisplayName when executed through maven.

The same test suites show correctly assigned names when run under eclipse (right-click --> Run as... --> JUnit Test).

This is an example of implemented tests:

@DisplayName(value="prog QA suite")
public class ProgQATest {

    @Test
    @Tag(value="TestProg")
    @DisplayName(value="prog QA present")
    public void testProg2QaPresent(String searchstring)
    {
        /* test code... */
    }
}

When run using eclipse show "prog QA suite" and "prog QA present" as names.

However, when run with "maven test" show "ProgQATest" and "testProg2QaPresent" as names.

The pom.xml used is:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.jupiter.version>5.3.2</junit.jupiter.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>com.github.pageobject</groupId>
        <artifactId>pageobject-core</artifactId>
        <version>1.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>4.0.0</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M1</version>
            <configuration>
                <forkCount>20</forkCount>
                <reuseForks>false</reuseForks>
                <testFailureIgnore>true</testFailureIgnore>
            </configuration>
        </plugin>
    </plugins>
</build>

Thanks a lot for your help!

pirxpilot
  • 131
  • 1
  • 5
  • 4
    It's known issue in Maven Surefire. See details at https://issues.apache.org/jira/browse/SUREFIRE-1546 – Sormuras Dec 05 '18 at 15:56
  • 1
    Thanks a lot. Is there an alternative to surefire I may use? – pirxpilot Dec 07 '18 at 07:52
  • 1
    The standalone "ConsoleLauncher" could be used via the `exec-maven-plugin` plugin: https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher I am also working on an alternative here: https://github.com/sormuras/junit-platform-maven-plugin ... but it needs some more time to ripe. – Sormuras Dec 07 '18 at 08:05
  • 1
    Thank you very much. I'll give it a try! – pirxpilot Dec 08 '18 at 13:54

1 Answers1

5

Check your @Test import. Mine was resolved when I used import org.junit.jupiter.api.Test; I had the same problem while using import org.junit.Test;

adiga
  • 34,372
  • 9
  • 61
  • 83
Roshan Joy
  • 131
  • 1
  • 6
  • Sounds logical :) but in my project it lead to problems to change this... too bad, I won't use @DisplayName until I totally migrate from JUnit 4 to JUnit5 :) – Zoette Aug 05 '21 at 05:25