Spawn JUnit 4 Tests Software

I have a JUnit 4 test that creates test data and approves a test condition for each individual file. If everything is correct, I get a green test.

If one of these data does not pass the test, the entire test is interrupted. I would like to have one JUnit test for each of the data. Is it possible to program JUnit tests programmatically so that I get many tests in my IDE?

The reason for this approach is to get a faster overview, which fails to complete, and to continue the remaining tests if the data fails.

+3
source share
1 answer

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 . .

+5

All Articles