I have a JUnit 4 test like following, I'm trying to upgrade JUnit to JUnit 5. I did some research about how to migrate JUnit 4 test to JUnit 5, but cannot find any useful information about how to migrate following case.
Anyone knows how to convert this test to JUnit 5?
@RunWith(Parameterized.class)
public class FibonacciTest {
@Parameters
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] { { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 } });
}
@Parameter(0)
public int fInput;
@Parameter(1)
public int fExpected;
@Test
public void test() {
assertEquals(fExpected, Fibonacci.compute(fInput));
}
}
Found a solution:
public class FibonacciTest {
public static Stream<Arguments> data() {
return Stream.of(
Arguments.arguments( 0, 0 ),
Arguments.arguments( 1, 1 ),
Arguments.arguments( 2, 1 ),
Arguments.arguments( 3, 2 ),
Arguments.arguments( 4, 3 ),
Arguments.arguments( 5, 5 ),
Arguments.arguments( 6, 8 )
);
}
@ParameterizedTest
@MethodSource("data")
public void test(int fInput, int fExpected) {
assertEquals(fExpected, Fibonacci.compute(fInput));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With