junit-team/junit5 · error · TemplateInvocationValidationException

Configuration error: You must configure at least one set of

Error message

Configuration error: You must configure at least one set of arguments for this @%s

What it means

Thrown by ParameterizedInvocationContextProvider.validateInvokedAtLeastOnce() as a TemplateInvocationValidationException when the stream of arguments from all @ArgumentsSource providers yields zero invocations and zero invocations are not explicitly allowed. This means every arguments source produced an empty stream.

Source

Thrown at junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationContextProvider.java:59

				.map(ArgumentsSource::value) //
				.map(clazz -> ParameterizedTestSpiInstantiator.instantiate(ArgumentsProvider.class, clazz,
					extensionContext)) //
				.map(provider -> AnnotationConsumerInitializer.initialize(declarationContext.getAnnotatedElement(),
					provider)) //
				.flatMap(provider -> arguments(provider, parameters, extensionContext)) //
				.map(arguments -> {
					invocationCount.incrementAndGet();
					return declarationContext.createInvocationContext(formatter, arguments, invocationCount.intValue());
				}) //
				.onClose(() -> validateInvokedAtLeastOnce(invocationCount.get(), declarationContext));
	}

	private static <T> void validateInvokedAtLeastOnce(long invocationCount,
			ParameterizedDeclarationContext<T> declarationContext) {
		if (invocationCount == 0 && !declarationContext.isAllowingZeroInvocations()) {
			String message = "Configuration error: You must configure at least one set of arguments for this @%s".formatted(
				declarationContext.getAnnotationName());
			throw new TemplateInvocationValidationException(message);
		}
	}

	private static List<ArgumentsSource> collectArgumentSources(ParameterizedDeclarationContext<?> declarationContext) {
		List<ArgumentsSource> argumentsSources = findRepeatableAnnotations(declarationContext.getAnnotatedElement(),
			ArgumentsSource.class);

		Preconditions.notEmpty(argumentsSources,
			() -> "Configuration error: You must configure at least one arguments source for this @%s".formatted(
				declarationContext.getAnnotationName()));

		return argumentsSources;
	}

	protected static Stream<? extends Arguments> arguments(ArgumentsProvider provider, ParameterDeclarations parameters,
			ExtensionContext context) {
		try {
			return provider.provideArguments(parameters, context);

View on GitHub (pinned to 956246301e)

Solutions

  1. Ensure at least one arguments source produces at least one row of arguments
  2. If zero arguments is a valid scenario, annotate with @ParameterizedClass(allowZeroInvocations = true) or @ParameterizedTest(allowZeroInvocations = true) (if supported by your version)
  3. Debug the @MethodSource method or ArgumentsProvider to confirm it returns a non-empty stream
  4. Check that @CsvSource has at least one value row (not just the annotation with no strings)

Example fix

// before
@ParameterizedTest
@MethodSource("emptyProvider")
void test(int x) { }
static Stream<Integer> emptyProvider() { return Stream.empty(); }

// after
@ParameterizedTest
@MethodSource("provider")
void test(int x) { }
static Stream<Integer> provider() { return Stream.of(1, 2, 3); }
Defensive patterns

Strategy: validation

Validate before calling

// Validate that your arguments provider returns at least one set:
static <T> void assertNonEmpty(Stream<? extends Arguments> stream, String name) {
    if (stream.findAny().isEmpty()) {
        throw new IllegalStateException(
            "Arguments source '" + name + "' produced zero argument sets");
    }
}
// Or use allowZeroInvocations if zero is valid:
// @ParameterizedTest(allowZeroInvocations = true)

Prevention

When it happens

Trigger: A @ParameterizedTest or @ParameterizedClass annotated with an arguments source that produces zero arguments: an empty @ValueSource, a @MethodSource method returning Stream.empty(), an empty @CsvSource (no rows), or a @ArgumentsSource provider whose provideArguments() returns an empty stream.

Common situations: A @MethodSource factory method that filters to empty for a particular data set, an empty @CsvSource annotation left over from refactoring, a dynamic arguments source that yields no rows in certain environments, or using @EmptySource expecting it to provide arguments but combining it incorrectly.

Related errors


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