Interface DisplayNameGenerator
-
- All Known Implementing Classes:
DisplayNameGenerator.IndicativeSentences,DisplayNameGenerator.ReplaceUnderscores,DisplayNameGenerator.Simple,DisplayNameGenerator.Standard
@API(status=STABLE, since="5.7") public interface DisplayNameGeneratorDisplayNameGeneratordefines 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
DisplayNameGeneratorcan 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@DisplayNameGenerationannotation.Built-in Implementations
- Since:
- 5.4
- See Also:
@DisplayName,@DisplayNameGeneration
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classDisplayNameGenerator.IndicativeSentencesDisplayNameGeneratorthat generates complete sentences.static classDisplayNameGenerator.ReplaceUnderscoresDisplayNameGeneratorthat replaces underscores with spaces.static classDisplayNameGenerator.SimpleSimpleDisplayNameGeneratorthat removes trailing parentheses for methods with no parameters.static classDisplayNameGenerator.StandardStandardDisplayNameGenerator.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_GENERATOR_PROPERTY_NAMEProperty name used to set the default display name generator class name: "junit.jupiter.displayname.generator.default"
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description java.lang.StringgenerateDisplayNameForClass(java.lang.Class<?> testClass)Generate a display name for the given top-level orstaticnested test class.default java.lang.StringgenerateDisplayNameForMethod(java.lang.Class<?> testClass, java.lang.reflect.Method testMethod)Deprecated.default java.lang.StringgenerateDisplayNameForMethod(java.util.List<java.lang.Class<?>> enclosingInstanceTypes, java.lang.Class<?> testClass, java.lang.reflect.Method testMethod)Generate a display name for the given method.default java.lang.StringgenerateDisplayNameForNestedClass(java.lang.Class<?> nestedClass)Deprecated.in favor ofgenerateDisplayNameForNestedClass(List, Class)default java.lang.StringgenerateDisplayNameForNestedClass(java.util.List<java.lang.Class<?>> enclosingInstanceTypes, java.lang.Class<?> nestedClass)Generate a display name for the given@Nestedinner test class.static DisplayNameGeneratorgetDisplayNameGenerator(java.lang.Class<?> generatorClass)Return theDisplayNameGeneratorinstance corresponding to the givenClass.static java.lang.StringparameterTypesAsString(java.lang.reflect.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 Detail
-
DEFAULT_GENERATOR_PROPERTY_NAME
@API(status=STABLE, since="5.9") static final java.lang.String DEFAULT_GENERATOR_PROPERTY_NAMEProperty 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:
- Constant Field Values
-
-
Method Detail
-
generateDisplayNameForClass
java.lang.String generateDisplayNameForClass(java.lang.Class<?> testClass)
Generate a display name for the given top-level orstaticnested 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; nevernull- Returns:
- the display name for the class; never blank
-
generateDisplayNameForNestedClass
@API(status=DEPRECATED, since="5.12") @Deprecated default java.lang.String generateDisplayNameForNestedClass(java.lang.Class<?> nestedClass)Deprecated.in favor ofgenerateDisplayNameForNestedClass(List, Class)Generate a display name for the given@Nestedinner 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; nevernull- Returns:
- the display name for the nested class; never blank
-
generateDisplayNameForNestedClass
@API(status=MAINTAINED, since="5.13.3") default java.lang.String generateDisplayNameForNestedClass(java.util.List<java.lang.Class<?>> enclosingInstanceTypes, java.lang.Class<?> nestedClass)Generate a display name for the given@Nestedinner 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, excludingnestedClass; nevernullnestedClass- the class to generate a name for; nevernull- Returns:
- the display name for the nested class; never blank
- Since:
- 5.12
-
generateDisplayNameForMethod
@API(status=DEPRECATED, since="5.12") @Deprecated default java.lang.String generateDisplayNameForMethod(java.lang.Class<?> testClass, java.lang.reflect.Method testMethod)Deprecated.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; nevernulltestMethod- method to generate a display name for; nevernull- Returns:
- the display name for the test; never blank
-
generateDisplayNameForMethod
@API(status=MAINTAINED, since="5.13.3") default java.lang.String generateDisplayNameForMethod(java.util.List<java.lang.Class<?>> enclosingInstanceTypes, java.lang.Class<?> testClass, java.lang.reflect.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, excludingtestClass; nevernulltestClass- the class the test method is invoked on; nevernulltestMethod- method to generate a display name for; nevernull- Returns:
- the display name for the test; never blank
- Since:
- 5.12
-
parameterTypesAsString
static java.lang.String parameterTypesAsString(java.lang.reflect.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; nevernull- Returns:
- a string representation of all parameter types of the supplied
method or
"()"if the method declares no parameters
-
getDisplayNameGenerator
static DisplayNameGenerator getDisplayNameGenerator(java.lang.Class<?> generatorClass)
Return theDisplayNameGeneratorinstance corresponding to the givenClass.- Parameters:
generatorClass- the generator'sClass; nevernull, has to be aDisplayNameGeneratorimplementation- Returns:
- a
DisplayNameGeneratorimplementation instance
-
-