简体   繁体   English

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

[英]Passing String array as a parameter to JUnit test

I'm using @Parameter for Field injection while writing a JUNIT test. 我在编写JUNIT测试时使用@Parameter进行字段注入。 Is it possible to pass a String array to the data object[][]. 是否可以将String数组传递给数据对象[] []。 I mean in the below code can I pass a string array like this 我的意思是在下面的代码中我可以传递这样的字符串数组

{"Input1","Input2",  {"file1","file2"}}

Code Snippet 代码段

@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);

  }
}

So I figured that we can create an array within arrays; 所以我想我们可以在数组中创建一个数组。 by creating a String array within the data Object like 通过在数据对象内创建一个String数组,例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Junit测试用于删除字符串数组中重复项的程序 - Junit Test for a program to remove duplicates in a string array 如何为junit中的字符串数组输入编写测试用例? - How to write test case for string array input in junit?(new to junit) NullPointerException 未通过 JUnit 测试 - NullPointerException not passing in JUnit test 传递字节数组; 通过junit测试,但是不能定期调用方法? - Passing byte array; passes junit test, but cant call method regularly? 类型不匹配将Scala JUnit测试中的数组传递给Java方法 - Type mismatch Passing an Array in Scala JUnit test to Java method 将带有数组参数的方法传递给驱动程序/测试文件? - Passing a method with an array parameter to a driver/test file? 如何在JUnit参数化测试中将数组作为测试参数传递? - How to pass an array as a test parameter in JUnit Parameterized testing? 使用数组参数在参数化JUnit测试中的反射异常 - Reflection Exception in parameterized JUnit test using array parameter 将字符串数组作为参数传递给函数java - Passing a string array as a parameter to a function java 如何在 junit 测试中为我的字符串数组初始化一个值? - How can I initialize a value to my string array in a junit test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM