TestNG 未找到测试.什么都没有运行 [英] TestNG No tests found. Nothing was run

查看:57
本文介绍了TestNG 未找到测试.什么都没有运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 TestNg 代码遇到了一个奇怪的问题.当我在没有 dataprovider 的情况下运行 testng 类时,我的测试成功运行但失败了,这对我来说是预期的.但是当我在课堂上保留我的数据提供者进行该测试时.Testng 给出了一个错误:[TestNG] 未找到测试.什么都没有运行以下是我的代码:请让我知道解决方案或建议我做错了什么 TestNG 版本:6.14.3

I am facing a strange problem with my TestNg code. When I run the testng class without dataprovider my tests run successfully and gets failed which is expected for me. But when I keep my dataprovider in the class for that test. Testng gives an error : [TestNG] No tests found. Nothing was run Below is my code: Please let me know the solution or suggest what I am doing wrong TestNG Version: 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();

    }
}

推荐答案

来自 TestNG 文档:

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

A @Test method specifies its Data Provider with the dataProvider attribute. This name must correspond to a method on the same class annotated with @DataProvider(name="...") with a matching name.

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

So you have to bind your data provider method to test method by name:

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

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

这篇关于TestNG 未找到测试.什么都没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆