Annotating a test parameter with @Aggregate aggregates all the supplied arguments into a single object.

Usage

@Aggregate can be applied to a parameter in a @ParameterizedTest.

@ParameterizedTest
@CsvSource({ "Jane, Doe, F, 1990-05-20", "John, Doe, M, 1990-10-22" })
void test(@Aggregate Person person) {
}

Limitations

The extension is meant to be used for simple use cases and has a couple of limitations.

  • The parameter object must have a public constructor.

  • The arguments must be in the same order as the constructor parameters.

  • The parameter object must be non-composite - it can not have another object(s) as fields.

This last point has a few exceptions based on JUnit 5 support for implicit type conversions. In the example above, if we have the following fields in the Person class:

private final String firstName;
private final String lastName;
private final Gender gender;
private final LocalDate birthday;

Then JUnit 5 will take care of the conversion from String to Gender and LocalDate. If you need to supply more complex objects to your tests, see if JSON arguments sources cover your use case.

Thread-Safety

This extension is safe to use during parallel test execution.