将字符串数组作为参数传递给JUnit测试
问题描述:
我在编写JUNIT测试时使用@Parameter进行字段注入。是否可以将一个String数组传递给数据对象[] []。我指的是在下面的代码 我可以传递一个字符串数组这样将字符串数组作为参数传递给JUnit测试
{"Input1","Input2", {"file1","file2"}}
代码段
@RunWith(Parameterized.class)
public class AModuleTest {
@Parameters
public static Iterable<Object[]> testData() {
Object[][] data = new Object[][]{
{"Input1","Input2", }
};
return Arrays.asList(data);
}
@Parameter(value=0) public String tabName;
@Parameter(value=1) public String fileSetName;
@Parameter(value=2) public String[] fileNames
@Test
public void ATest(){
//here I'm just passing those parameters to these functions clickTab, Navigate()...
clickTab(tabName);
Navigate(fileSet);
}
}
答
所以我想,我们可以创建阵列内的阵列;通过在数据对象内创建一个String数组,如
Object[][] data = new Object[][]{
{"Input1","Input2", new String[] {"file1", "file2"} }
};