JUnit Reports — Test Method Descriptions

后端 未结 4 875
盖世英雄少女心
盖世英雄少女心 2021-02-05 04:03

I am trying to see if there is a way to include \"descriptive text\" in my junit reports by way of javadocs. JUnit 4 doesnt seem to support the \'description\' attribute for the

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 05:02

    In JUnit 5 there is a way to annotate every test with a @DisplayName. The declared test classes can have text, special characters and emojis.

    The declared text on each test is visible by test runners and test reports.


    The Javadoc says:

    public @interface DisplayName

    @DisplayName is used to declare a custom display name for the annotated test class or test method. Display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.

    And the User Guide:

    import org.junit.gen5.api.DisplayName;
    import org.junit.gen5.api.Test;
    
    @DisplayName("A special test case")
    class DisplayNameDemo {
    
        @Test
        @DisplayName("Custom test name containing spaces")
        void testWithDisplayNameContainingSpaces() {
        }
    
        @Test
        @DisplayName("╯°□°)╯")
        void testWithDisplayNameContainingSpecialCharacters() {
        }
    
        @Test
        @DisplayName("

提交回复
热议问题