NetBeans Junit5 Tests-Output ignore DisplayName Nested-Format

Viewed 508

I do not get the names from the annoations "@DisplayName" as a test result in NetBeans. Only the names of the test functions are shown. The grouped display of the nested tests is also ignored.

enter image description here

Source code

@DisplayName("test facade")
public class TestFacadeTest {

    @BeforeAll
    public static void setUpClass() {
    }

    @AfterAll
    public static void tearDownClass() {
    }

    @BeforeEach
    public void setUp() {
    }

    @AfterEach
    public void tearDown() {
    }

    @Test
    @DisplayName("senseless test")
    public void test(){
        Assertions.assertTrue(true);
    }

    @Nested
    @DisplayName("tests - compareStringNullSave")
    class CompateStringNullSaveTestGroup {
    
        @BeforeEach
        public void setUp() { 
        }
    
        @Test
        @DisplayName("both identical")
        public void Test1(){
            String str1 = "Test123";
            String str2 = "Test123";
            Assertions.assertTrue(TestFacade.compareStringNullSave(str1, str2));
            Assertions.assertTrue(TestFacade.compareStringNullSave(str2, str1));
        }
    
        @Test
        @DisplayName("Identical text but different uppercase and lowercase letters")
        public void Test2(){
            String str1 = "Test123";
            String str2 = "test123";
            Assertions.assertFalse(TestFacade.compareStringNullSave(str1, str2));
            Assertions.assertFalse(TestFacade.compareStringNullSave(str2, str1));
        }
    } 
}

Extract from the pom.xml

<dependencies>
    [...]
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.7.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>5.7.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.7.0</version>
        <scope>test</scope>
    </dependency>
    [...]
</dependencies>

<build>
    <plugins>
        [...]
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
            <configuration>
                <properties>
                    <configurationParameters>
                        junit.jupiter.conditions.deactivate = *
                        junit.jupiter.extensions.autodetection.enabled = true
                        junit.jupiter.testinstance.lifecycle.default = per_class
                    </configurationParameters>
                </properties>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>
    </plugins>
</build>

What do I have to set so that the test display in NetBeans shows the DisplayNames and uses the nested grouping?

NetBeans version: 12.0 Java version: 11 (OpenJDK)

1 Answers

Maven added support for the @Display annotation in the 3.0.0.0-M4 version of the surefire plugin. Also, you need to configure the parameters of statelessTestsetReporter and statelessTestsetInfoReporter extensions to allow for NetBeans to match display names correctly.

So currently (01.2021), you can use 3.0.0.0-M4 or newer versions of the surefire plugin, and the version of JUnit should be more than 5.5.2. Something like that should work:

<plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <statelessTestsetReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5Xml30StatelessReporter">
                    <version>3.0</version>
                    <usePhrasedFileName>true</usePhrasedFileName>
                    <usePhrasedTestSuiteClassName>true</usePhrasedTestSuiteClassName>
                    <usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
                    <usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
                </statelessTestsetReporter>
                <statelessTestsetInfoReporter implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter">
                    <usePhrasedClassNameInRunning>true</usePhrasedClassNameInRunning>
                </statelessTestsetInfoReporter>
                 <properties>
                    <configurationParameters>
                       junit.jupiter.conditions.deactivate = *
                       junit.jupiter.extensions.autodetection.enabled = true
                       junit.jupiter.testinstance.lifecycle.default = per_class
                    </configurationParameters>
                </properties>
            </configuration>                                
        </plugin>
    </plugins>

Here how it looks in my case:

@DisplayName("Display Name of class")
public class testClassSimple {

    @Test
    @DisplayName("Display name of method 1")
    public void testMethod1() {
    }
    
    @Test
    @DisplayName("Display name of method 2")
    public void testMethod2() {
    }
}

enter image description here

As for nested grouping and the @Nested annotation, currently, NetBeans doesn't support nested grouping of test results in the test result window. Probably it's better to use different classes for such tests instead of nested classes.

Related