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 | Class and Description |
|---|---|
| public static class | DisplayNameGenerator.
|
| public static class | DisplayNameGenerator.
|
| public static class | DisplayNameGenerator.
Simple |
| public static class | DisplayNameGenerator.
Standard |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | DEFAULT_GENERATOR_PROPERTY_NAME
Property name used to set the default display name generator class name: Supported Values Supported values include fully qualified class names for types that
implement |
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: the display name for the class; never blankthe class to generate a name for; never testClass)nullGenerate a display name for the given top-level or |
| public default String | Returns: the display name for the test; never blankthe class the test method is invoked on; never testClass, Method nullmethod to generate a display name for; never testMethod)null
Deprecated
since 5.12. in favor of
generateDisplayNameForMethod(List, Class, Method)
Generate a display name for the given method. |
| public default String | Returns: the display name for the test; never blankthe runtime types of the enclosing
instances for the test class, ordered from outermost to innermost,
excluding enclosingInstanceTypes, Class<?> testClass; never nullthe class the test method is invoked on; never testClass, Method nullmethod to generate a display name for; never testMethod)nullGenerate a display name for the given method. |
| public default String | Returns: the display name for the nested class; never blankthe class to generate a name for; never nestedClass)null
Deprecated
since 5.12. in favor of
generateDisplayNameForNestedClass(List, Class)
Generate a display name for the given |
| public default String | Returns: the display name for the nested class; never blankthe runtime types of the enclosing
instances for the test class, ordered from outermost to innermost,
excluding enclosingInstanceTypes, Class<?> nestedClass; never nullthe class to generate a name for; never nestedClass)nullGenerate a display name for the given |
| public static DisplayNameGenerator | Returns: aDisplayNameGenerator implementation instancethe generator's generatorClass)Class; never null,
has to be a DisplayNameGenerator implementationReturn the |
| public static String | Returns: a string representation of all parameter types of the supplied method or"()" if the method declares no parametersthe method from to extract the parameter types from; never
method)nullGenerate 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. |
| DEFAULT_GENERATOR_PROPERTY_NAME | back to summary |
|---|---|
| public static final String DEFAULT_GENERATOR_PROPERTY_NAME Property name used to set the default display name generator class name: Supported ValuesSupported values include fully qualified class names for types that
implement If not specified, the default is
| |
| generateDisplayNameForClass | back to summary |
|---|---|
| public String generateDisplayNameForClass(Class<?> testClass) Generate a display name for the given top-level or If this method returns | |
| generateDisplayNameForMethod | back to summary |
|---|---|
| public default String generateDisplayNameForMethod(Class<?> testClass, Method testMethod)
Generate a display name for the given method. If this method returns Implementation Note The class instance supplied as
| |
| generateDisplayNameForMethod | back to summary |
|---|---|
| public default String generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod) Generate a display name for the given method. If this method returns Implementation Note The classes supplied as
| |
| generateDisplayNameForNestedClass | back to summary |
|---|---|
| public default String generateDisplayNameForNestedClass(Class<?> nestedClass)
Generate a display name for the given If this method returns
| |
| generateDisplayNameForNestedClass | back to summary |
|---|---|
| public default String generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> nestedClass) Generate a display name for the given If this method returns Implementation Note The classes supplied as
| |
| getDisplayNameGenerator | back to summary |
|---|---|
| public static DisplayNameGenerator getDisplayNameGenerator(Class<?> generatorClass) Return the
| |
| parameterTypesAsString | back to summary |
|---|---|
| public 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. | |
DisplayNameGenerator that generates complete sentences.
This generator generates display names that build up complete sentences
by concatenating the names of the test and the enclosing classes. The
sentence fragments are concatenated using a separator. The separator and
the display name generator for individual sentence fragments can be configured
via the @IndicativeSentencesGeneration
annotation.
If you do not want to rely on a display name generator for individual
sentence fragments, you can supply custom text for individual fragments
via the @SentenceFragment annotation.
| Modifier and Type | Class and Description |
|---|---|
| public static @interface | DisplayNameGenerator.
|
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final DisplayNameGenerator | |
| private static final Predicate |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static Optional | Returns: anOptional containing the annotation, potentially empty if not foundthe test class on which to find the annotation; never testClass, List<Class<?>> nullthe runtime types of the enclosing
instances; never enclosingInstanceTypes)nullFind the first |
| private static Optional | Returns: anOptional containing the annotation, potentially empty if not foundthe test class on which to find the annotation; never testClass, List<Class<?>> nullthe runtime types of the enclosing
instances; never enclosingInstanceTypes)nullFind the first |
| public String | generateDisplayNameForClass(Class<?> testClass)
Implements org. Generate a display name for the given top-level or |
| public String | generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod)
Overrides default org. Generate a display name for the given method. |
| public String | generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> nestedClass)
Overrides default org. Generate a display name for the given |
| private static String | Returns: the sentence fragment separatorthe test class to search on for testClass, List<Class<?>> @IndicativeSentencesGenerationthe runtime types of the enclosing
instances; never enclosingInstanceTypes)nullGet the sentence fragment separator. |
| private static DisplayNameGenerator | Returns: theDisplayNameGenerator instance to usethe test class to search on for testClass, List<Class<?>> @IndicativeSentencesGenerationthe runtime types of the enclosing
instances; never enclosingInstanceTypes)nullGet the display name generator to use for the supplied test class. |
| private String | |
| private static @Nullable String |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final DisplayNameGenerator INSTANCE | |
| notIndicativeSentences | back to summary |
|---|---|
| private static final Predicate<Class<?>> notIndicativeSentences | |
| IndicativeSentences | back to summary |
|---|---|
| public IndicativeSentences() | |
| findDisplayNameGeneration | back to summary |
|---|---|
| private static Optional Find the first
| |
| findIndicativeSentencesGeneration | back to summary |
|---|---|
| private static Optional Find the first
| |
| generateDisplayNameForClass | back to summary |
|---|---|
| public String generateDisplayNameForClass(Class<?> testClass) Implements org. Doc from org. Generate a display name for the given top-level or If this method returns
| |
| generateDisplayNameForMethod | back to summary |
|---|---|
| public String generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod) Overrides default org. Doc from org. Generate a display name for the given method. If this method returns
| |
| generateDisplayNameForNestedClass | back to summary |
|---|---|
| public String generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> nestedClass) Overrides default org. Doc from org. Generate a display name for the given If this method returns
| |
| getFragmentSeparator | back to summary |
|---|---|
| private static String getFragmentSeparator(Class<?> testClass, List<Class<?>> enclosingInstanceTypes) Get the sentence fragment separator. If | |
| getGeneratorFor | back to summary |
|---|---|
| private static DisplayNameGenerator getGeneratorFor(Class<?> testClass, List<Class<?>> enclosingInstanceTypes) Get the display name generator to use for the supplied test class. If
| |
| getSentenceBeginning | back to summary |
|---|---|
| private String getSentenceBeginning(Class<?> testClass, List<Class<?>> enclosingInstanceTypes) | |
| getSentenceFragment | back to summary |
|---|---|
| private static @Nullable String getSentenceFragment(AnnotatedElement element) | |
@SentenceFragment is used to configure a custom sentence fragment
for a sentence generated by the IndicativeSentences
DisplayNameGenerator.
Note that @DisplayName always takes precedence
over @SentenceFragment.
| Modifier and Type | Method and Description |
|---|---|
| public String | Returns: a custom sentence fragment; never blank or consisting solely of whitespaceCustom sentence fragment for the annotated class or method. |
| value | back to summary |
|---|---|
| public String value() Custom sentence fragment for the annotated class or method.
| |
DisplayNameGenerator that replaces underscores with spaces.
This generator extends the functionality of Simple by
replacing all underscores ('_') found in class and method names
with spaces (' ').
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final DisplayNameGenerator |
| Access | Constructor and Description |
|---|---|
| public |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final DisplayNameGenerator INSTANCE Hides org. | |
| ReplaceUnderscores | back to summary |
|---|---|
| public ReplaceUnderscores() | |
| generateDisplayNameForClass | back to summary |
|---|---|
| public String generateDisplayNameForClass(Class<?> testClass) Overrides org. Implements org. Doc from org. Generate a display name for the given top-level or If this method returns
| |
| generateDisplayNameForMethod | back to summary |
|---|---|
| public String generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod) Overrides org. Overrides default org. Doc from org. Generate a display name for the given method. If this method returns
| |
| generateDisplayNameForNestedClass | back to summary |
|---|---|
| public String generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> nestedClass) Overrides org. Overrides default org. Doc from org. Generate a display name for the given If this method returns
| |
| replaceUnderscores | back to summary |
|---|---|
| private static String replaceUnderscores(String name) | |
DisplayNameGenerator that removes trailing parentheses
for methods with no parameters.
This generator extends the functionality of Standard by
removing parentheses ('()') found at the end of method names
with no parameters.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final DisplayNameGenerator |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod)
Overrides org. Overrides default org. Generate a display name for the given method. |
| private static boolean |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final DisplayNameGenerator INSTANCE Hides org. | |
| Simple | back to summary |
|---|---|
| public Simple() | |
| generateDisplayNameForMethod | back to summary |
|---|---|
| public String generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod) Overrides org. Overrides default org. Doc from org. Generate a display name for the given method. If this method returns
| |
| hasParameters | back to summary |
|---|---|
| private static boolean hasParameters(Method method) | |
DisplayNameGenerator.
This implementation matches the standard display name generation behavior in place since JUnit Jupiter was introduced.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final DisplayNameGenerator |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | generateDisplayNameForClass(Class<?> testClass)
Implements org. Generate a display name for the given top-level or |
| public String | generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod)
Overrides default org. Generate a display name for the given method. |
| public String | generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> nestedClass)
Overrides default org. Generate a display name for the given |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final DisplayNameGenerator INSTANCE | |
| Standard | back to summary |
|---|---|
| public Standard() | |
| generateDisplayNameForClass | back to summary |
|---|---|
| public String generateDisplayNameForClass(Class<?> testClass) Implements org. Doc from org. Generate a display name for the given top-level or If this method returns
| |
| generateDisplayNameForMethod | back to summary |
|---|---|
| public String generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod) Overrides default org. Doc from org. Generate a display name for the given method. If this method returns
| |
| generateDisplayNameForNestedClass | back to summary |
|---|---|
| public String generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> nestedClass) Overrides default org. Doc from org. Generate a display name for the given If this method returns
| |