userimage

Execute the same test case with multiple time having different number of data JUnit

I have a method which take integer as an input and give some result. But to test this method I am writing different test cases proving single data at a time. e.g I want test with 4,6,89 then I written 3 new methods for this.

Is there any way I can compete this in a single shot(means by using one method)?


userimage

Please have a look from junit 4.4 theories:

import org.junit.Test;
import org.junit.experimental.theories.*;
import org.junit.runner.RunWith;

@RunWith(Theories.class)
public class PrimeTest {

    @Theory
    public void isPrime(int candidate) {
          // called with candidate=1, candidate=2, etc etc  
    }

    public static @DataPoints int[] candidates = {1, 2, 3, 4, 5};
}


Answer is