@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.
@DisplayName,
@DisplayNameGeneration| Modifier and Type | Interface and Description |
|---|---|
static class |
DisplayNameGenerator.IndicativeSentences
DisplayNameGenerator that generates complete sentences. |
static class |
DisplayNameGenerator.ReplaceUnderscores
DisplayNameGenerator that replaces underscores with spaces. |
static class |
DisplayNameGenerator.Simple
Simple
DisplayNameGenerator that removes trailing parentheses
for methods with no parameters. |
static class |
DisplayNameGenerator.Standard
Standard
DisplayNameGenerator. |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_GENERATOR_PROPERTY_NAME
Property name used to set the default display name generator class name:
"junit.jupiter.displayname.generator.default"
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
generateDisplayNameForClass(java.lang.Class<?> testClass)
Generate a display name for the given top-level or
static nested test class. |
java.lang.String |
generateDisplayNameForMethod(java.lang.Class<?> testClass,
java.lang.reflect.Method testMethod)
Generate a display name for the given method.
|
java.lang.String |
generateDisplayNameForNestedClass(java.lang.Class<?> nestedClass)
Generate a display name for the given
@Nested inner test class. |
static DisplayNameGenerator |
getDisplayNameGenerator(java.lang.Class<?> generatorClass)
Return the
DisplayNameGenerator instance corresponding to the
given Class. |
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.
|
@API(status=STABLE,
since="5.9")
static final java.lang.String DEFAULT_GENERATOR_PROPERTY_NAME
Supported values include fully qualified class names for types that
implement DisplayNameGenerator.
If not specified, the default is
DisplayNameGenerator.Standard.
java.lang.String generateDisplayNameForClass(java.lang.Class<?> testClass)
static nested test class.
If it returns null, the default display name generator will be used instead.
testClass - the class to generate a name for; never nulljava.lang.String generateDisplayNameForNestedClass(java.lang.Class<?> nestedClass)
@Nested inner test class.
If it returns null, the default display name generator will be used instead.
nestedClass - the class to generate a name for; never nulljava.lang.String generateDisplayNameForMethod(java.lang.Class<?> testClass,
java.lang.reflect.Method testMethod)
If it returns null, the default display name generator will be used instead.
testClass - the class the test method is invoked on; never nulltestMethod - method to generate a display name for; never nullstatic java.lang.String parameterTypesAsString(java.lang.reflect.Method method)
method - the method from to extract the parameter types from; never
null"()" if the method declares no parametersstatic DisplayNameGenerator getDisplayNameGenerator(java.lang.Class<?> generatorClass)
DisplayNameGenerator instance corresponding to the
given Class.generatorClass - the generator's Class; never null,
has to be a DisplayNameGenerator implementationDisplayNameGenerator implementation instance