Testng不会单独计算数据提供者测试

时间:2015-12-02 23:11:48

标签: java testng testng-dataprovider

这是我的数据提供者

@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个测试。我错过了什么?

2 个答案:

答案 0 :(得分: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 
    }
}

有关详情,请参阅文档here

答案 1 :(得分:0)

仅针对每个数据集迭代DataProviders,只会产生测试的累积结果,而不是每次迭代的结果。

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

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