Slide 35
Slide 35 text
import org.junit.jupiter.params.*;
import java.util.stream.Stream;
public class DataDrivenTest {
private final ArithmeticOperation arithmeticOperation =↵
new ArithmeticOperation();
@ParameterizedTest(name = "can add {0} to {1} and receive {2}")
@MethodSource("additionProvider")
void canAddAndAssertExactResult(int a, int b, int result) {
assertEquals(result, arithmeticOperation.add(a, b));
}
static Stream additionProvider() {
return Stream.of(
Arguments.of(1, 3, 4),
Arguments.of(3, 4, 7)
);
}
}
Data-driven tests