The differences between the following 2 cases are
a> The type of variable 'arr'. In the first case, its type is Integer[], while in the second case its type is int[].
b> We can see from where I marked as "// here" that in the case 1 it needs Integer[][][]. while in the case 2 it needs int[][].
Both of case 1 and case 2 work. So my question comes:
Why Junit require I return a 3-dimentional Integer array in the data() method in case 1 when the test data is a 1-dimentional Integer array. I expected it should be 2 - dimentional Integer array because in the case 2 I return a 2 - dimentional int array in the data() method and it is easy to understand it and it works. But when I tried to return 2-dimentional Integer array in the data() method in case 1 as
@Parameterized.Parameters(name = "test with {index}")
public static Iterable<Integer[]> data() {
return Arrays.asList(new Integer[][]{
{3, 1, 4, 6, 7, 9},
{9, 8, 7, 6, 5, 4},
});
}
Junit reported "java.lang.IllegalArgumentException: wrong number of arguments". Please help me if you know the reason.
I searched Junit documents and many other pages without satisfied answer. Please help.My Junit version is 4.12.
case 1
@RunWith(Parameterized.class)
public class MyTest {
@Parameterized.Parameters(name = "test with {index}")
public static Iterable<Integer[][]> data() {
//here: My question is why it can not be Integer[][]
return Arrays.asList(new Integer[][][]{
{{3, 1, 4, 6, 7, 9}},
{{9, 8, 7, 6, 5, 4}},
});
}
private Integer[] arr;
public MyTest(Integer[] arr) {
this.arr = arr;
}
public methodTest(int[] arr) {
// ignore the code here
}
}
case 2
@RunWith(Parameterized.class)
public class MyTest {
@Parameterized.Parameters(name = "test with {index}")
public static Iterable<int[]> data() {
//here int[][] works
return Arrays.asList(new int[][]{
{3, 1, 4, 6, 7, 9},
{9, 8, 7, 6, 5, 4},
}
private int[] arr;
public MyTest(int[] arr) {
this.arr = arr;
}
public methodTest(int[] arr) {
// ignore the code here
}
}
@RunWith(Parameterized.class)annotation before both of your test classes?