Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@DisplayName not working when tests executed through maven

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!

like image 784
ilikeblues Avatar asked Dec 05 '18 14:12

ilikeblues


1 Answers

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;

like image 72
Roshan Joy Avatar answered Sep 19 '22 20:09

Roshan Joy