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: junit.jupiter.displayname.generator.default 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)null Generate a display name for the given top-level or |
public String | Returns: the display name for the test; never blankthe class the test method is invoked on; never testClass, Method null method to generate a display name for; never testMethod)null Generate a display name for the given method. |
public String | Returns: the display name for the nested class; never blankthe class to generate a name for; never nestedClass)null Generate 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)null 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. |
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: junit.jupiter.displayname.generator.default 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 it returns |
generateDisplayNameForMethod | back to summary |
---|---|
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) Generate a display name for the given method. If it returns Implementation Note The class instance supplied as |
generateDisplayNameForNestedClass | back to summary |
---|---|
public String generateDisplayNameForNestedClass(Class<?> nestedClass) Generate a display name for the given If it returns |
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.
Modifier and Type | Field and Description |
---|---|
pack-priv static final DisplayNameGenerator |
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)null Find 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)null Find the first |
public String | generateDisplayNameForClass(Class<?>
the class to generate a name for; never testClass)null Implements org. static nested test class.
|
public String | generateDisplayNameForMethod(Class<?>
the class the test method is invoked on; never testClass, Method null method to generate a display name for; never testMethod)null Implements org. |
public String | generateDisplayNameForNestedClass(Class<?>
the class to generate a name for; never nestedClass)null Implements org. @Nested inner test class.
|
private static String | Returns: the sentence fragment separatorthe test class to search on for testClass)@IndicativeSentencesGeneration Get the sentence fragment separator. |
private static DisplayNameGenerator | Returns: theDisplayNameGenerator instance to usethe test class to search on for testClass)@IndicativeSentencesGeneration Get the display name generator to use for the supplied test class. |
private String | |
private static Predicate |
INSTANCE | back to summary |
---|---|
pack-priv static final DisplayNameGenerator INSTANCE |
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 it returns |
generateDisplayNameForMethod | back to summary |
---|---|
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) Implements org. Doc from org. Generate a display name for the given method. If it returns |
generateDisplayNameForNestedClass | back to summary |
---|---|
public String generateDisplayNameForNestedClass(Class<?> nestedClass) Implements org. Doc from org. Generate a display name for the given If it returns |
getFragmentSeparator | back to summary |
---|---|
private static String getFragmentSeparator(Class<?> testClass) Get the sentence fragment separator. If |
getGeneratorFor | back to summary |
---|---|
private static DisplayNameGenerator getGeneratorFor(Class<?> testClass) Get the display name generator to use for the supplied test class. If
|
getSentenceBeginning | back to summary |
---|---|
private String getSentenceBeginning(Class<?> testClass) |
not | back to summary |
---|---|
private static Predicate |
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 it returns |
generateDisplayNameForMethod | back to summary |
---|---|
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) Overrides org. Implements org. Doc from org. Generate a display name for the given method. If it returns |
generateDisplayNameForNestedClass | back to summary |
---|---|
public String generateDisplayNameForNestedClass(Class<?> nestedClass) Overrides org. Implements org. Doc from org. Generate a display name for the given If it 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(Class<?>
the class the test method is invoked on; never testClass, Method null method to generate a display name for; never testMethod)null Overrides org. Implements org. |
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(Class<?> testClass, Method testMethod) Overrides org. Implements org. Doc from org. Generate a display name for the given method. If it 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 5.0 was released.
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<?>
the class to generate a name for; never testClass)null Implements org. static nested test class.
|
public String | generateDisplayNameForMethod(Class<?>
the class the test method is invoked on; never testClass, Method null method to generate a display name for; never testMethod)null Implements org. |
public String | generateDisplayNameForNestedClass(Class<?>
the class to generate a name for; never nestedClass)null Implements org. @Nested inner test class.
|
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 it returns |
generateDisplayNameForMethod | back to summary |
---|---|
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) Implements org. Doc from org. Generate a display name for the given method. If it returns |
generateDisplayNameForNestedClass | back to summary |
---|---|
public String generateDisplayNameForNestedClass(Class<?> nestedClass) Implements org. Doc from org. Generate a display name for the given If it returns |