Interface DisplayNameGenerator

  • All Known Implementing Classes:
    DisplayNameGenerator.ReplaceUnderscores, DisplayNameGenerator.Standard

    @API(status=EXPERIMENTAL,
         since="5.4")
    public interface DisplayNameGenerator
    DisplayNameGenerator defines the SPI for generating display names programmatically.

    Display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.

    Concrete implementations must have a default constructor.

    Since:
    5.4
    See Also:
    @DisplayName, @DisplayNameGeneration
    • Method Detail

      • generateDisplayNameForClass

        String generateDisplayNameForClass​(Class<?> testClass)
        Generate a display name for the given top-level or static nested test class.
        Parameters:
        testClass - the class to generate a name for; never null
        Returns:
        the display name for the class; never null or blank
      • generateDisplayNameForNestedClass

        String generateDisplayNameForNestedClass​(Class<?> nestedClass)
        Generate a display name for the given @Nested inner test class.
        Parameters:
        nestedClass - the class to generate a name for; never null
        Returns:
        the display name for the nested class; never null or blank
      • generateDisplayNameForMethod

        String generateDisplayNameForMethod​(Class<?> testClass,
                                            Method testMethod)
        Generate a display name for the given method.
        Parameters:
        testClass - the class the test method is invoked on; never null
        testMethod - method to generate a display name for; never null
        Returns:
        the display name for the test; never null or blank
      • parameterTypesAsString

        static String parameterTypesAsString​(Method method)
        Generate a string representation of the formal parameters of the supplied method, consisting of the simple names of the parameter types, separated by commas, and enclosed in parentheses.
        Parameters:
        method - the method from to extract the parameter types from; never null
        Returns:
        a string representation of all parameter types of the supplied method or "()" if the method declares no parameters