It looks like you want to write a parameterized test (which performs accurate checks on different data sets).
Parameterized. , :
@RunWith(Parameterized.class)
public class FibonacciTest {
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {{ 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 } });
}
private final int input;
private final int expected;
public FibonacciTest(final int input, final int expected) {
this.input = input;
this. expected = expected;
}
@Test
public void test() {
assertEquals(expected, Fibonacci.compute(input));
}
}
, data() , test(). (, , ).
, , @Test . .