You could also use DynamicTest (those have added benefit of being checked by compiler, so you won't pass in incorrect type), this will generate three tests with a set of two parameters:
@TestFactory
Stream<DynamicTest> test() {
return Map.of(
"a", 1,
"b", 2,
"foo", 3
).entrySet().stream().map(
e -> DynamicTest.dynamicTest(
"test %s, %d".formatted(e.getKey(), e.getValue()),
() -> // some assertions on e.getKey and e.getValue
)
);
}
Parametrized Tests are good if you operate on Strings only, or test full enums (without filtering, because if you filter you again use strings to do it - fails at runtime, with dynamic test it would fail during compile time)
For dynamic tests you can use any source you like, above example is with map, but you could use something more readable like:
@TestFactory
Stream<DynamicTest> test() {
record TestData(String arg1, int arg2) {}
return Stream.of(
new TestData("a", 1),
new TestData("b", 2),
new TestData("foo", 3)
).map(
e -> DynamicTest.dynamicTest(
"test %s, %d".formatted(e.getKey(), e.getValue()),
() -> // some assertions on e.getKey and e.getValue
)
);
}