- All Known Implementing Classes:
DisplayNameGenerator.IndicativeSentences
,DisplayNameGenerator.ReplaceUnderscores
,DisplayNameGenerator.Simple
,DisplayNameGenerator.Standard
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:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
DisplayNameGenerator
that generates complete sentences.static class
DisplayNameGenerator
that replaces underscores with spaces.static class
SimpleDisplayNameGenerator
that removes trailing parentheses for methods with no parameters.static class
StandardDisplayNameGenerator
. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Property name used to set the default display name generator class name: "junit.jupiter.displayname.generator.default" -
Method Summary
Modifier and TypeMethodDescriptiongenerateDisplayNameForClass
(Class<?> testClass) Generate a display name for the given top-level orstatic
nested test class.generateDisplayNameForMethod
(Class<?> testClass, Method testMethod) Generate a display name for the given method.generateDisplayNameForNestedClass
(Class<?> nestedClass) Generate a display name for the given@Nested
inner test class.static DisplayNameGenerator
getDisplayNameGenerator
(Class<?> generatorClass) Return theDisplayNameGenerator
instance corresponding to the givenClass
.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.
-
Field Details
-
DEFAULT_GENERATOR_PROPERTY_NAME
Property name used to set the default display name generator class name: "junit.jupiter.displayname.generator.default"Supported Values
Supported values include fully qualified class names for types that implement
DisplayNameGenerator
.If not specified, the default is
DisplayNameGenerator.Standard
.- Since:
- 5.5
- See Also:
-
-
Method Details
-
generateDisplayNameForClass
Generate a display name for the given top-level orstatic
nested test class.If it returns
null
, the default display name generator will be used instead.- Parameters:
testClass
- the class to generate a name for; nevernull
- Returns:
- the display name for the class; never blank
-
generateDisplayNameForNestedClass
Generate a display name for the given@Nested
inner test class.If it returns
null
, the default display name generator will be used instead.- Parameters:
nestedClass
- the class to generate a name for; nevernull
- Returns:
- the display name for the nested class; never blank
-
generateDisplayNameForMethod
Generate a display name for the given method.If it returns
null
, the default display name generator will be used instead.- Parameters:
testClass
- the class the test method is invoked on; nevernull
testMethod
- method to generate a display name for; nevernull
- Returns:
- the display name for the test; never blank
- Implementation Note:
- The class instance supplied as
testClass
may differ from the class returned bytestMethod.getDeclaringClass()
— for example, when a test method is inherited from a superclass.
-
parameterTypesAsString
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; nevernull
- Returns:
- a string representation of all parameter types of the supplied
method or
"()"
if the method declares no parameters
-
getDisplayNameGenerator
Return theDisplayNameGenerator
instance corresponding to the givenClass
.- Parameters:
generatorClass
- the generator'sClass
; nevernull
, has to be aDisplayNameGenerator
implementation- Returns:
- a
DisplayNameGenerator
implementation instance
-