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 during construction of ParameterizedInvocationNameFormatter when the display name pattern (set via the 'name' attribute of @ParameterizedTest or @ParameterizedClass, or the junit.jupiter.params.displayName.pattern configuration parameter) cannot be parsed. The parser attempts to break the pattern into PartialFormatter segments (placeholders like {0}, {index}, {arguments}, etc.). Any exception during this parse phase — such as an invalid MessageFormat pattern — is wrapped in this JUnitException with the original cause attached.
Solutions
- Inspect the nested cause exception for the specific parse error — it will identify the exact position and nature of the syntax error
- Simplify the pattern to a known-good baseline (e.g., "#[{index}] {arguments}") and add complexity incrementally
- Ensure all braces in the pattern are balanced and MessageFormat special characters are properly quoted with single quotes
- Check that any custom placeholders are supported by the current JUnit version
Example fix
// before — unbalanced brace in display name pattern
@ParameterizedTest(name = "#{index} {0")
void test(String input) { }
// after — balanced braces
@ParameterizedTest(name = "#{index} {0}")
void test(String input) { }
// For literal braces in MessageFormat, use single quotes:
@ParameterizedTest(name = "#[{index}] ''{0}''")
void test(String input) { } Defensive patterns
Strategy: try-catch
Validate before calling
// Validate the display name pattern before running tests
import java.text.MessageFormat;
static void validateDisplayNamePattern(String pattern) {
try {
new MessageFormat(pattern);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid display name pattern: " + pattern, e);
}
// Check for balanced braces
long opens = pattern.chars().filter(c -> c == '{').count();
long closes = pattern.chars().filter(c -> c == '}').count();
if (opens != closes) {
throw new IllegalArgumentException("Unbalanced braces in pattern: " + pattern);
}
} Try / catch
// In test infrastructure setup, catch and report invalid patterns early
try {
validateDisplayNamePattern(pattern);
} catch (IllegalArgumentException e) {
logger.error("Display name pattern validation failed for @ParameterizedTest", e);
// Fall back to default pattern
pattern = ParameterizedTest.DEFAULT_DISPLAY_NAME;
} Prevention
- Test display name patterns with a simple parameterized test before applying them to complex tests
- Use JUnit's built-in placeholders ({index}, {arguments}, {0}) rather than complex MessageFormat syntax
- Quote literal braces with single quotes in MessageFormat patterns (e.g., '{0}') to avoid parse errors
When it happens
Trigger: Set @ParameterizedTest(name = "{0}") where {0} is actually valid, but use an invalid MessageFormat pattern like unbalanced braces (e.g., name = "{0") or name = "{a}"). Using a placeholder the formatter doesn't recognize, or a pattern with illegal MessageFormat syntax such as '{' without proper quoting.
Common situations: Developers customizing display names for parameterized tests with complex patterns. Migration from JUnit 4 parameterized display names that used different placeholder syntax. Copy-pasting a MessageFormat pattern that works in production code but conflicts with JUnit's custom placeholder parsing (which adds {index}, {arguments}, {0}, {arguments-set-name} on top of MessageFormat).
Related errors
- Failed to format display name for parameterized test. See…
- When the display name pattern for a @
- Configuration error: .
- Configuration error: You must configure at least one set of…
- Constructor injection is not supported for…
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/6982ddc59a81cbf7.
Report an issue: GitHub.
Appendix: 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 f070c699a0)