将String数组作为参数传递给JUnit测试

时间:2016-07-06 18:20:34

标签: java arrays junit junit4 parameterized

我在编写JUNIT测试时使用@Parameter进行Field注入。是否可以将String数组传递给数据对象[] []。我的意思是在下面的代码中 我可以传递像这样的字符串数组

{"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);

  }
}

1 个答案:

答案 0 :(得分:0)

所以我想我们可以在数组中创建一个数组;通过在数据对象中创建一个String数组,如

 Object[][] data = new Object[][]{
    {"Input1","Input2", new String[] {"file1", "file2"} }
};