我这有 4 个 ArrayList 的参数,expCode,expMessage,actCode,actMessage
怎么在 junit 里让这 4 个参数里每个值一一对应去测试,网上找了 junit 参数化测试都 2 个参数的对比
是哪个方法啊?
(iexpCode 对比 actCode) && ( expMessage 对比 actMessage) 两个都为 true 的话就是通过 不是吗?
@RunWith(Parameterized.class)
public class ResultParamTest {
private int actCode;
private String actMessage;
private int expCode;
private String expMessage;
public ResultParamTest(int expCode, int actCode, String expMessage, String actMessage) {
this.expCode = expCode;
this.actCode = actCode;
this.expMessage = expMessage;
this.actMessage = actMessage;
}
@Parameterized.Parameters
public static Collection prepareData() throws IOException {
ResultParam resultParam = new ResultParam("test_case.xlsx", 0);
ArrayList<Integer> a = resultParam.expCode();
ArrayList<Integer> b = resultParam.actCode();
ArrayList<String> c = resultParam.expMessage();
ArrayList<String> d = resultParam.actMessage();
Object[][] objects = {{a.get(0), b.get(0), c.get(0), d.get(0)}, {a.get(1), b.get(1), c.get(1), d.get(1)},........{}....{}};
return Arrays.asList(objects);
}
@Test
public void testResultParam() throws IOException {
Assert.assertEquals(expCode, actCode);
Assert.assertEquals(expMessage, actMessage);
}
}
求大神告诉下,我要怎么把 a,b,c,d 这些值给赋值到 objects 这个二维数组里去,实在找不到方法了
RunWith(Parameterized.class)
public class ResultParamTest {
private int actCode;
private String actMessage;
private int expCode;
private String expMessage;
public ResultParamTest(int expCode, int actCode, String expMessage, String actMessage) {
this.expCode = expCode;
this.actCode = actCode;
this.expMessage = expMessage;
this.actMessage = actMessage;
}
@Parameterized.Parameters
public static Collection prepareData() throws IOException {
ResultParam resultParam = new ResultParam("test_case.xlsx", 0);
ArrayList<Integer> a = resultParam.expCode();
ArrayList<Integer> b = resultParam.actCode();
ArrayList<String> c = resultParam.expMessage();
ArrayList<String> d = resultParam.actMessage();
Object[][] objects = {{a.get(0), b.get(0), c.get(0), d.get(0)}, {a.get(1), b.get(1), c.get(1), d.get(1)},........{}....{}};
return Arrays.asList(objects);
}
@Test
public void testResultParam() throws IOException {
Assert.assertEquals(expCode, actCode);
Assert.assertEquals(expMessage, actMessage);
}
}
求大神告诉下,我要怎么把 a,b,c,d 这些值给赋值到 objects 这个二维数组里去,实在找不到方法了
我已经写出来了,你参考下 https://testerhome.com/topics/9306