There are a few options for running tests with different sets of parameters.
JUnit Parameterized
You could use different test classes inside another class with the Enclosed runner.
@RunWith(Enclosed.class)
public class TestClass {
@RunWith(Parameterized.class)
public static class FirstParameterizedTest {
@Parameters
public static Object[][] data() {
...
}
@Test
public void someTest() {
...
}
}
public static class SecondParameterizedTest {
@Parameters
public static Object[][] data() {
...
}
@Test
public void anotherTest() {
...
}
}
}
JUnitParams
JUnitParams has plenty of ways for specifying the parameters. See https://github.com/Pragmatists/JUnitParams/blob/master/src/test/java/junitparams/usage/SamplesOfUsageTest.java
Here is a simple example.
@RunWith(JUnitParamsRunner.class)
public class TestClass {
@Test
@Parameters({"AAA,1", "BBB,2"})
public void paramsInAnnotation(String p1, Integer p2) {
...
}
}
Burst
Burst uses Enums for specifying test parameters. Different test methods can use different Enums.
@RunWith(BurstJUnit4.class)
public class TestClass {
enum FirstSetOfParameters {
A(1,2),
B(2,3)
final int x1, x2;
FirstSetOfParameters( int x1, int x2) {
this.x1=x1;
this.x2=x2;
}
}
@Test
public void firstTest( FirstSetOfParameters parameters) {
...
}
enum SecondSetOfParameters {
A(1),
B(2)
final int x1;
SecondSetOfParameters(int x1) {
this.x1=x1;
}
}
@Test
public void secondTest(SecondSetOfParameters parameters) {
...
}
}
Other libraries
There are some more libraries. You may have a look at Zohhak and junit-dataprovider.