I am working with junit5 and I want to create Parameterized Test in nested class. For example:
class CardTest {
@Nested
class Cost {
Stream<Arguments> cards() {
return Stream.of(
Arguments.of(Card.common(0, Color.RED), 0),
/** Other Data **/
Arguments.of(Card.choseColor(), 50)
);
}
@MethodSource("cards")
@ParameterizedTest
void cardCost(Card card, int cost) {
assertThat(card.cost())
.isEqualTo(cost);
}
}
/** Some other nested classes or simple methods **/
}
The problem is @MethodSource required that specified method must be static
. But Java not allowed static method in non-static inner classes. If I create class Cost static
then it won't be collected by junit
.
What should I do to resolve this issue?