Using object is also possible using Junit @Parameters
.
Example:-
@RunWith(Parameterized.class)
public class TestParameter {
@Parameter(value=0)
public int expected;
@Parameter(value=1)
public int first;
@Parameter(value=2)
public int second;
private Calculator myCalculator;
@Parameters(name = "Test : {index} : add({1}+{2})= Expecting {0}")//name will be shared among all tests
public static Collection addNumbers() {
return Arrays.asList(new Integer[][] { { 3, 2, 1 }, { 5, 2, 3 }, { 9, 8, 1 }, { 200, 50, 150 } });
}
@Test
public void testAddWithParameters() {
myCalculator = new Calculator();
System.out.println(first + " & " + second + " Expected = " + expected);
assertEquals(expected, myCalculator.Add(first, second));
}
}