我需要在 testng.xml 文件中传递一个整数数组,因为我使用它作为我的配置文件来对我编写的方法运行多个测试,以使其成为数据驱动的。
这个方法:
@Test(groups="runnable")
@Parameters({"fName","lName","childAges"})
public void test(String firstName, String lastName, Integer[] childAges);
在我的 testng.xml 文件中:
<test name="WyomingComplex4Kids (Positive)">
<parameter name="fName" value="John"/>
<parameter name="lName" value="Johnson"/>
<parameter name="childAges" value="{10,7,3,6}"/>
<parameter name="server" value="https://example.server.com/app/someRoute"/>
<parameter name="port" value="443"/>
<groups>
<run>
<include name="runnable"/>
</run>
</groups>
<classes>
<class name = "com.somecompany.test.EligibilityComplex1"/>
</classes>
</test>
接受一个包含 child 年龄的整数数组,这似乎不起作用。我对 testng 和一般测试很陌生。有人可以帮我吗?我听说使用 dataprovider tp 传递复杂的对象(即像数组或列表),但我无法理解它是如何工作的或如何在我的测试中使用它。因此,我们将不胜感激任何帮助,谢谢。
最佳答案
testng 中没有指定将 {"sdf","sdf"} 转换为数组的模式。您将收到“不支持的类型参数”错误。引用代码(convertType方法)here 。仅转换基本数据类型。
如果要转换为数组,需要在数组中进行拆分和转换。
数据提供者只是帮助您使用不同的数据运行相同的测试。在这种情况下,如果您从 Excel 中读取所有数据,您仍然需要通过代码创建数组。
关于java - 如何传递整数数组testng.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26239247/