https://www.cnblogs.com/beifucangqiong/p/11266894.html

测试类


    @Test(dataProvider = "provider")
    public void getName(String name) {

    }

    @DataProvider(name = "provider")
    public Iterator provider() throws IOException {
        String str = "D:\\pythonspacen\\pyt\\sku.txt";
        return new TxtIterator(new File(str));
    }

测试数据


import java.io.*;
import java.util.Iterator;

/**
 * @author liwen
 * @Title: TxtIterator
 * @Description: 数据加载
 * @date 2019/11/27 / 13:54
 */
public class TxtIterator implements Iterator {

    //数据文件
    File txtFile;
    BufferedReader bs;
    String currentLine;

    public TxtIterator(File txtFile) throws IOException {
        super();
        this.txtFile = txtFile;
        try {
            bs = new BufferedReader(new FileReader(txtFile));
        } catch (FileNotFoundException e) {
            System.out.println("文件找不到");
            e.printStackTrace();
        }
        currentLine = bs.readLine();
    }

    @Override
    public boolean hasNext() {
        if (currentLine != null) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public String[] next() {
        String returnLine = currentLine;
        try {
            currentLine = bs.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return returnLine.split(",");
    }
}