1

这是我的数据提供者

@DataProvider(name = "arrayBuilder")
public Object[][] parameterTestProvider() {
    //Code to obtain retailerIDList
    String[] retailerIDArray = retailerIDList.toArray(new String[retailerIDList.size()]);
assertEquals(1295, retailerIDList.size(), "Expected 1295, found " + retailerIDList.size() + " docs");
    return new Object[][] {{retailerIDArray}};
}

这是我的测试

@Test(dataProvider = "arrayBuilder", invocationCount = 1, threadPoolSize = 1)
public void getRetailer(String[] retailerIDList) {

    for (String retailer_ID : retailerIDList) {
        //Code that uses the retailerID 
 }

当我执行此测试时,TestNG 输出将“getRetailer”列为唯一测试。我有 1295 条数据提供者返回的记录,我希望报告 1295 条测试。我错过了什么?

4

2 回答 2

1

请使用这个,它应该工作。您需要返回对象数组,其中每一行是要用于测试的一行数据。然后只有它会出现在报告中。您正在做的是向它发送一个数组,因此它将其视为单个测试。

    @DataProvider(name="provideData")
    public  Iterator<Object[]> provideData() throws Exception
    {
        List<Object[]> data = new ArrayList<Object[]>();
        String[] retailerIDArray = retailerIDList.toArray(new String[retailerIDList.size()]);
        assertEquals(1295, retailerIDList.size(), "Expected 1295, found " + retailerIDList.size() + " docs");
        for(String retailerID : retailerIDArray ){

            data.add(new Object[]{retailerID});

        }

        return data.iterator(); 

    }

@Test(dataProvider = "provideData")
public void getRetailer(String retailerIDList) {

    for (String retailer_ID : retailerIDList) {
        //Code that uses the retailerID 
    }
}

有关更多信息,请在此处查看文档

于 2015-12-04T17:03:02.860 回答
0

单独的 DataProviders 在对每个数据集进行迭代时,只会产生测试的累积结果,而不是每次迭代的结果。

尝试在 DataProvider 旁边使用测试工厂,以获得测试的每次迭代的单独结果。

http://testng.org/doc/documentation-main.html#factories

于 2015-12-04T06:19:16.247 回答