junit-team/junit5 · error · JUnitException
The display name pattern defined for the parameterized test
Error message
The display name pattern defined for the parameterized test is invalid. See nested exception for further details.
What it means
Thrown by the ParameterizedInvocationNameFormatter constructor when parsing the display name pattern (the 'name' attribute of @ParameterizedTest or @ParameterizedClass) throws an exception. The pattern is parsed into PartialFormatter segments that may contain java.text.MessageFormat sub-patterns for literal text containing curly braces. Invalid MessageFormat syntax in these segments triggers the nested exception.
Source
Thrown at junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java:94
.orElse(512);
Preconditions.condition(argumentMaxLength > 0,
() -> ARGUMENT_MAX_LENGTH_KEY + " must be a positive number: " + argumentMaxLength);
return new ParameterizedInvocationNameFormatter(pattern, extensionContext.getDisplayName(), declarationContext,
argumentMaxLength);
}
private final PartialFormatter[] partialFormatters;
ParameterizedInvocationNameFormatter(String pattern, String displayName,
ParameterizedDeclarationContext<?> declarationContext, int argumentMaxLength) {
try {
this.partialFormatters = parse(pattern, displayName, declarationContext, argumentMaxLength);
}
catch (Exception ex) {
String message = "The display name pattern defined for the parameterized test is invalid. "
+ "See nested exception for further details.";
throw new JUnitException(message, ex);
}
}
String format(int invocationIndex, EvaluatedArgumentSet arguments, boolean quoteTextArguments) {
try {
return formatSafely(invocationIndex, arguments, quoteTextArguments);
}
catch (Exception ex) {
String message = "Failed to format display name for parameterized test. "
+ "See nested exception for further details.";
throw new JUnitException(message, ex);
}
}
@SuppressWarnings("JdkObsolete")
private String formatSafely(int invocationIndex, EvaluatedArgumentSet arguments, boolean quoteTextArguments) {
ArgumentsContext context = new ArgumentsContext(invocationIndex, arguments.getConsumedArguments(),
arguments.getName(), quoteTextArguments);View on GitHub (pinned to 956246301e)
Solutions
- Use the documented JUnit placeholders: {index}, {displayName}, {arguments}, {argumentsWithNames}, {argumentSetName}, {0}, {1}, etc.
- If you need literal curly braces in the display name, escape them as MessageFormat requires: use ''{'' and ''}'' (single-quote escapes)
- Simplify the pattern to isolate which segment is malformed, then re-add complexity
- Check the nested exception in the stack trace for the exact MessageFormat parse error
Example fix
// before
@ParameterizedTest(name = "test { for {0}")
void test(int x) { }
// after (escape literal braces or remove them)
@ParameterizedTest(name = "test for {0}")
void test(int x) { } Defensive patterns
Strategy: validation
Validate before calling
// Validate the display name pattern before applying it:
static void validateDisplayNamePattern(String pattern) {
try {
// Test that any literal brace segments parse as MessageFormat
if (pattern.contains("{" )) {
new MessageFormat(pattern.replaceAll("\\{index}|\\{arguments}|\\{displayName", ""));
}
} catch (Exception e) {
throw new IllegalArgumentException("Invalid display name pattern: " + pattern, e);
}
}
// Simpler: stick to documented placeholders and avoid raw curly braces Prevention
- Use only documented JUnit placeholders: {index}, {displayName}, {arguments}, {argumentsWithNames}, {argumentSetName}, {argumentSetNameOrArgumentsWithNames}
- Escape literal curly braces in MessageFormat segments with single quotes: '{' and '}'
- Avoid complex MessageFormat type specifiers unless you have tested them
- Start with a simple pattern like '[{index}] {arguments}' and add complexity incrementally
When it happens
Trigger: Setting name = "{0} test" or name = "test {" on @ParameterizedTest(name=...) or @ParameterizedClass(name=...) where the curly-brace segment is not a valid MessageFormat pattern. For example, an unmatched single brace '{' or a malformed format choice/type specifier.
Common situations: Using a display name pattern that contains literal curly braces for formatting but has syntax errors (e.g., '{' without closing '}', '{0,date}' with an unsupported format type). Confusing JUnit placeholders like {index} (which are fine) with MessageFormat patterns like {0}.
Related errors
- Failed to format display name for parameterized test. See ne
- When the display name pattern for a @%s contains %s, the arg
- Configuration error: You must configure at least one set of
- Unsupported argument count validation mode: <mode>
- Constructor injection is not supported for @ParameterizedCla
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/6982ddc59a81cbf7.json.
Report an issue: GitHub.