Consider my test class:
public class TestClass {
static public class Vegetable {
String name
public Vegetable(String name) { ... }
}
static public class Fruit {
String name;
List<Vegetable> assignedVegs;
public Fruit(String name, List<Vegetable> vegs) { ... }
}
List<Fruit> fruits = asList(
new Fruit("Orange", asList(new Vegetable("Potato"))),
new Fruit("Apple", asList(new Vegetable("Potato"), new Vegetable("Carot")))
);
@ParametrizedTest
public void test(Fruit f, Vegetable v) { ... }
}
I would like to run my test
method with the following data combinations
- ["Orange", "Potato"],
- ["Apple", "Potato"],
- ["Apple", "Carot"],
however, without adding further elements to fruits
or changing the signature of test
. What is the best way to achieve this using for example a @MethodSource
? Or is there any more junit-like way to achieve a similar result? And what would be the approach if the parameter space was even higher dimensional?
Aucun commentaire:
Enregistrer un commentaire