【问题标题】:Passing String array as a parameter to JUnit test将字符串数组作为参数传递给 JUnit 测试
【发布时间】:2016-07-06 18:20:33
【问题描述】:

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

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

  }
}

【问题讨论】:

    标签: java arrays junit junit4 parameterized


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多