TestNG找不到测试。什么都没跑

时间:2018-12-03 09:01:30

标签: java testng

我的TestNg代码遇到一个奇怪的问题。当我在没有dataprovider的情况下运行testng类时,我的测试会成功运行并失败,这对我来说是预期的。 但是,当我将我的dataprovider放在该测试的类中时。 Testng给出一个错误: [TestNG]找不到测试。一无所有 以下是我的代码:请让我知道解决方案或提出我在做错的TestNG版本:6.14.3

package api.tests;

import org.testng.annotations.Test;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.HashMap;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.testng.SkipException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import api.config.Base;
import api.data.xlutility_read;
import api.services.GooglePlace;

public class GoogleAddPlaceTest extends Base {

    public static GooglePlace GP = null;
    public static xlutility_read ER = null;
    public HashMap<String, String> requestMap = null;

    public GoogleAddPlaceTest() throws IOException {
        super();

    }

    @BeforeMethod
    public void Setup() throws IOException {
        GP = new GooglePlace();
        Base.setResources();
        // ER =
    }

    @DataProvider()
    public Object[][] getExcelRows() throws InvalidFormatException, IOException {

        ER = new xlutility_read("D:\\ApiData.xlsx");

        Object[][] object = new Object[ER.getRowCount(1) - 2][1];
        int rNum = 3;
        while (!ER.isRowEmpty(1, rNum) && rNum <= ER.getRowCount(1)) {
            requestMap = new HashMap<>();
            for (int j = 0; j < 1; j++) {

                requestMap = ER.ExcelToHashMap(1, rNum);

            }
            object[rNum - 3][0] = requestMap;
            rNum++;
        }

        ER.closeFile();

        return object;

    }

    @Test(dataProvider = "getExcelRows")
    public void testAddPlaceApi(HashMap<Object, Object> requestMap) throws IOException {
        try {
            ER = new xlutility_read("D:\\ApiData.xlsx");
        } catch (InvalidFormatException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        int testRowNum = ER.getRowNum(1, "testAddPlaceApi", 0);
        if (testRowNum != -1) {
            if (ER.getCellData(1, testRowNum, 1).equalsIgnoreCase("y")) {
                GP.deletePlaceApi(GP.addPlaceApi(GP.jsonAsMap(requestMap)));
            } else {
                throw new SkipException("Test case run Flag is N : So Skipped.");
            }
        }

    }

    @AfterMethod
    public void tearUp() throws IOException {
        Base.freeResources();

    }
}

2 个答案:

答案 0 :(得分:1)

来自TestNG documentation

  

@Test方法使用dataProvider指定其数据提供程序   属性。此名称必须对应于同一类上的方法   带有@DataProvider(name =“ ...”)并带有匹配的名称。

因此,您必须将数据提供者方法绑定到名称测试方法:

@DataProvider(name = "data")
public Object[][] getExcelRows() throws InvalidFormatException, IOException {
   ...
}

@Test(dataProvider = "data")
public void testAddPlaceApi(HashMap<Object, Object> requestMap) throws IOException {
   ...
}

答案 1 :(得分:0)

您是否使用Excel工作表存储测试数据?如果是,则再添加一列作为“执行”,将值设为Y。