使用建構函式

import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;
import java.util.*;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class SimpleParmeterizedTest {
    @Parameters
    public static Collection<Object[]> data(){
        return Arrays.asList(new Object[][]{
                {5, false}, {6, true}, {8, true}, {11, false}    
        });
    }
    
    private int input;
    private boolean expected;
    
    public SimpleParmeterizedTest(int input, boolean expected){
        this.input = input;
        this.expected = expected;
    }
    
    @Test
    public void testIsEven(){
        assertThat(isEven(input), is(expected));
    }
}

data() 中,你提供要在測試中使用的資料。Junit 將遍歷資料並使用每組資料執行測試。