Search code examples
junitjunit-runner

Run a list of jUnit runners


I have some test suites that in essence looks like

@Test
public void test1_2() {
    test(1,2);
}
@Test
public void test1_3() {
    test(1,3);
}
@Test
public void test4_5() {
    test(4,5);
}
@Test
public void test4_9() {
    test(4,9);
}

// and so forth

private void test(int i, int j) throws AssertionError{
    // ...
}

(This is not the actual tests, but the essence, each @Test method only calls one method)

So my thinking was that I could use @RunWith for a custom BlockJUnit4ClassRunner which accepts a List of jUnit Runners.

How would this be achived? Or is there a better way to do it?


Solution

  • Why not use @Parameter ?

    @RunWith(Parameterized.class)
    public class YourTest{
    
     private int i;
     private int j;
    
     public Parameter(int i, int j) {
        this.i= i;
        this.j= j;
     }
    
     @Parameters
     public static Collection<Object[]> data() {
          Object[][] data = new Object[][] { { 1, 2 }, { 1,3 }, { 4,5 }, { 4,9 } };
          return Arrays.asList(data);
     }
    
     @Test
     public void test() throws InterruptedException {
        //use i & j
     } 
    }