我有一个JUnit 4测试,如下所示,我正在尝试将JUnit升级到JUnit 5。我做了一些关于如何将 JUnit 4 测试迁移到 JUnit 5 的研究,但找不到有关如何迁移以下情况的任何有用信息。
有人知道如何将此测试转换为 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));
}
}
找到了一个解决方案:
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));
}
}