junit-team/junit5 · error · JUnitException
Failed to format display name for parameterized test. See ne
Error message
Failed to format display name for parameterized test. See nested exception for further details.
What it means
Thrown by ParameterizedInvocationNameFormatter.format() during each test invocation when formatting the display name with actual argument values throws an exception. Unlike error 47 (which is a parse-time pattern error), this occurs at runtime when MessageFormat.format() fails on the real argument values.
Source
Thrown at junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java:105
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);
StringBuffer result = new StringBuffer(); // used instead of StringBuilder so MessageFormat can append directly
for (PartialFormatter partialFormatter : this.partialFormatters) {
partialFormatter.append(context, result);
}
return result.toString();
}
private PartialFormatter[] parse(String pattern, String displayName,
ParameterizedDeclarationContext<?> declarationContext, int argumentMaxLength) {
List<PartialFormatter> result = new ArrayList<>();View on GitHub (pinned to 956246301e)
Solutions
- Review the nested exception to find which argument and format specifier caused the failure
- Simplify the name pattern to plain JUnit placeholders ({index}, {arguments}) to avoid MessageFormat type conflicts
- Ensure all argument rows provide values compatible with any MessageFormat type specifiers in the pattern
- If mixing types across invocations, remove the specific format type (e.g., ,number) and use a plain {0} placeholder
Example fix
// before
@ParameterizedTest(name = "{0,number,currency}")
@CsvSource({ "1.50", "N/A" })
void test(String val) { }
// after (no type-specific MessageFormat on mixed-type arguments)
@ParameterizedTest(name = "{0}")
@CsvSource({ "1.50", "N/A" })
void test(String val) { } Defensive patterns
Strategy: validation
Validate before calling
// Ensure argument values are compatible with any MessageFormat specifiers:
@ParameterizedTest(name = "{0}") // safe for all types
@CsvSource({"1", "text"})
void test(String val) { }
// If using {0,number,...}, ensure all rows provide compatible types Prevention
- Avoid MessageFormat type specifiers (e.g., {0,number,currency}) when argument types vary across invocations
- Use plain placeholders ({0}, {arguments}) that work with any argument type
- Test the display name pattern with all representative argument rows, not just the first
- Check the nested exception for the specific MessageFormat.format failure
When it happens
Trigger: The display name pattern is syntactically valid but a MessageFormat sub-segment fails when applied to the actual argument values — e.g., a {0,number,currency} format applied to a non-numeric argument, or a format specifier that conflicts with the runtime type of an argument.
Common situations: A @ParameterizedTest with name = "{0,number,#.##}" but one of the CSV argument rows contains a non-numeric string. An argument type changes between rows causing some invocations to format fine and others to fail. Using a MessageFormat type specifier incompatible with the argument's actual type.
Related errors
- The display name pattern defined for the parameterized test
- When the display name pattern for a @%s contains %s, the arg
- Unsupported argument count validation mode: <mode>
- Configuration error: You must configure at least one set of
- Argument at index [%d] with value [%s] and type [%s] could n
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/a8462cc2d71d439d.json.
Report an issue: GitHub.