junit-team/junit5 · error · JUnitException

Invalid %s '%s' set via the '%s' configuration parameter.

Error message

Invalid %s '%s' set via the '%s' configuration parameter.

What it means

Thrown as a JUnitException by EnumConfigurationParameterConverter.convert when a configuration parameter value (from junit-platform.properties, system property, or launcher ConfigurationParameters) cannot be parsed into the expected enum type. The converter uppercases and strips the value, then calls Enum.valueOf; any failure (illegal constant name) is wrapped. Used for ExecutionMode (parallel execution mode), Lifecycle (test instance lifecycle mode), CleanupMode (cleanup mode), ExtensionContextScope (extension context scope), TimeoutMode (timeout mode), and ThreadMode (timeout thread mode).

Source

Thrown at junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/config/EnumConfigurationParameterConverter.java:61

		return configParams.get(key) //
				.map(value -> convert(key, value));
	}

	public Optional<E> get(ExtensionContext extensionContext, String key) {
		return extensionContext.getConfigurationParameter(key, value -> convert(key, value));
	}

	private E convert(String key, String value) {
		String constantName = null;
		try {
			constantName = value.strip().toUpperCase(Locale.ROOT);
			E result = Enum.valueOf(enumType, constantName);
			logger.config(() -> "Using %s '%s' set via the '%s' configuration parameter.".formatted(enumDisplayName,
				result, key));
			return result;
		}
		catch (Exception ex) {
			throw new JUnitException("Invalid %s '%s' set via the '%s' configuration parameter.".formatted(
				enumDisplayName, constantName, key));
		}
	}

}

View on GitHub (pinned to 956246301e)

Solutions

  1. Check the error message for the enumDisplayName (e.g. 'parallel execution mode') and the offending value, then set it to a valid constant of that enum (e.g. PARALLEL, CONCURRENT for ExecutionMode; PER_METHOD or PER_CLASS for Lifecycle; ON_SUCCESS or ON_TRAVERSAL for CleanupMode).
  2. Open the enum's Javadoc (ExecutionMode, Lifecycle, CleanupMode, ExtensionContextScope, TimeoutMode, ThreadMode) and copy a constant name verbatim.
  3. Validate the file against the JUnit version actually on the classpath — constants are occasionally renamed across major versions.

Example fix

// before (junit-platform.properties)
junit.jupiter.testinstance.lifecycle.default = PER_METHODS

// after
junit.jupiter.testinstance.lifecycle.default = PER_METHOD
Defensive patterns

Strategy: validation

Validate before calling

// Validate a config value against its enum before launching JUnit
public static <E extends Enum<E>> void validate(Class<E> enumType, String key, String raw) {
    try {
        Enum.valueOf(enumType, raw.strip().toUpperCase(java.util.Locale.ROOT));
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
            "Invalid value '" + raw + "' for " + key + ". Valid: " + java.util.Arrays.toString(enumType.getEnumConstants()));
    }
}
// usage: validate(Lifecycle.class, "junit.jupiter.testinstance.lifecycle.default", "PER_METHOD");

Type guard

static <E extends Enum<E>> boolean isValidEnumValue(Class<E> enumType, String raw) {
    try { Enum.valueOf(enumType, raw.strip().toUpperCase(java.util.Locale.ROOT)); return true; }
    catch (Exception e) { return false; }
}

Prevention

When it happens

Trigger: Setting a configuration parameter such as junit.jupiter.testinstance.lifecycle.default = PER_METHODS (typo, no such constant), or junit.jupiter.execution.parallel.mode.default = PARALLELL, or junit.jupiter.cleanup.mode.default = stric. Any value that is not an exact (case-insensitive) match of a constant in the target enum.

Common situations: Typos in junit-platform.properties; copying a value from outdated documentation; version change where an enum constant was renamed or removed; locale-specific case folding (the converter uses Locale.ROOT so this is rare, but non-ASCII letters would fail).

Related errors


AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04). Data as JSON: /data/errors/13ed00353d406d33.json. Report an issue: GitHub.