简体   繁体   中英

Can I run a JUnit test Case as “multiple tests” by different parameters?

@RunWith(Theories.class)
public class ExampleTest {

   @Theory
   @Test
   public void isEven(int value)
   {
       assertEquals(value%2,0);
   }
public static @DataPoints int[] values =  valueBuilder();

private static int[] valueBuilder(){
    int[] returnValue= {1,2,3,4,5,6,7,8,9,10};
    return returnValue;
}
}

I was able to run a test for different sets of data like from above.

Current Approach:

  1. Runs as a single test Case for all 10 items of data. (more like a for loop).

  2. One Failure causes the test to stop.

Need:

-> Some approach to run this test as 10 independents tests. Show failed cases as failed and continue running for other data items.

Thanks In Advance.

Use Parameterized Runner Test

@RunWith(Parameterized.class)
public class ExampleTest {

    @Theory
    @Test
    public void isEven(int value)
    {
       assertEquals(value%2,0);
    }
    public static @DataPoints int[] values =  valueBuilder();

    // Provide data
    @Parameters
    private static int[] valueBuilder(){
        int[] returnValue= {1,2,3,4,5,6,7,8,9,10};
        return returnValue;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM