Interface DisplayNameGenerator

All Known Implementing Classes:
DisplayNameGenerator.IndicativeSentences, DisplayNameGenerator.ReplaceUnderscores, DisplayNameGenerator.Simple, DisplayNameGenerator.Standard

@API(status=STABLE, since="5.7") 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.

A DisplayNameGenerator can be configured globally for the entire test suite via the "junit.jupiter.displayname.generator.default" configuration parameter (see the User Guide for details) or locally for a test class via the @DisplayNameGeneration annotation.

Built-in Implementations

Since:
5.4
See Also:
  • Field Details

  • Method Details

    • generateDisplayNameForClass

      String generateDisplayNameForClass(Class<?> testClass)
      Generate a display name for the given top-level or static nested test class.

      If this method returns null, the default display name generator will be used instead.

      Parameters:
      testClass - the class to generate a name for; never null
      Returns:
      the display name for the class; never blank
    • generateDisplayNameForNestedClass

      @API(status=DEPRECATED, since="5.12") @Deprecated default String generateDisplayNameForNestedClass(Class<?> nestedClass)
      Generate a display name for the given @Nested inner test class.

      If this method returns null, the default display name generator will be used instead.

      Parameters:
      nestedClass - the class to generate a name for; never null
      Returns:
      the display name for the nested class; never blank
    • generateDisplayNameForNestedClass

      @API(status=EXPERIMENTAL, since="5.12") default String generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> nestedClass)
      Generate a display name for the given @Nested inner test class.

      If this method returns null, the default display name generator will be used instead.

      Parameters:
      enclosingInstanceTypes - the runtime types of the enclosing instances for the test class, ordered from outermost to innermost, excluding nestedClass; never null
      nestedClass - the class to generate a name for; never null
      Returns:
      the display name for the nested class; never blank
      Since:
      5.12
      Implementation Note:
      The classes supplied as enclosingInstanceTypes may differ from the classes returned from invocations of Class.getEnclosingClass() — for example, when a nested test class is inherited from a superclass.
    • generateDisplayNameForMethod

      @API(status=DEPRECATED, since="5.12") @Deprecated default String generateDisplayNameForMethod(Class<?> testClass, Method testMethod)
      Generate a display name for the given method.

      If this method returns null, the default display name generator will be used instead.

      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 blank
      Implementation Note:
      The class instance supplied as testClass may differ from the class returned by testMethod.getDeclaringClass() — for example, when a test method is inherited from a superclass.
    • generateDisplayNameForMethod

      @API(status=EXPERIMENTAL, since="5.12") default String generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod)
      Generate a display name for the given method.

      If this method returns null, the default display name generator will be used instead.

      Parameters:
      enclosingInstanceTypes - the runtime types of the enclosing instances for the test class, ordered from outermost to innermost, excluding testClass; never null
      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 blank
      Since:
      5.12
      Implementation Note:
      The classes supplied as enclosingInstanceTypes may differ from the classes returned from invocations of Class.getEnclosingClass() — for example, when a nested test class is inherited from a superclass. Similarly, the class instance supplied as testClass may differ from the class returned by testMethod.getDeclaringClass() — for example, when a test method is inherited from a superclass.
    • 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
    • getDisplayNameGenerator

      static DisplayNameGenerator getDisplayNameGenerator(Class<?> generatorClass)
      Return the DisplayNameGenerator instance corresponding to the given Class.
      Parameters:
      generatorClass - the generator's Class; never null, has to be a DisplayNameGenerator implementation
      Returns:
      a DisplayNameGenerator implementation instance