zoukankan      html  css  js  c++  java
  • testng dataprovider 的几种用法以及Java中的二维数组


    @Log4j
    public class testDataprovider { @DataProvider(name = "DP1") public Object [][] createData() { Object[][] retObjArr = { {"001","Jack","London"}, {"002","John","New York"}, {"003","Mary","Miami"}, {"004","George","California"} }; return retObjArr; } @Test(dataProvider = "DP1") public void testEmployeeData(String empid, String empName, String city) { log.info(empid); log.info(empName); log.info(city); }
    二、直接使用二维数组
    @DataProvider(name = "datasource")
        public Object[][] createDataSource(){
    
            return new Object[][]{
                    {1,2,3,3},
                    {2,1,3,3},
                    {5,3,4,5},
                    {2,3,2,3}
            };
        }
    
        @Test(dataProvider = "datasource")
        public void verifyGetMaxResult(int fir, int sec, int thd,int result)
        {
             assert result == calc.getMax(fir,sec,thd);
        }

    三、使用Map<string, string>

        @SneakyThrows
        @DataProvider(name = "refund")
        private Map[][] testDataForRefund() {
            String excelFile = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "data" + File.separator + "webgate" + File.separator + "TestData.xlsx";
            ExcelUtil.read(excelFile);
            return ExcelUtil.getData("退款");
        }
    
    @Test(dataProvider = "refund")
        public void TestRefund01(Map<String, String> data) throws Exception {
            executeTestCase(data);
        }

     上面可以看出dataprovider生成的是Java的二维数组,下面讲一下Java的二维数组:

    //定义二维数组写法2        不规则数组
    class numfive
    {
    public static void main(String[] args)
    {
    long[][] numfive=new long[5][];     //定义一个long类型的不规则数组
    numfive[0]=new long[5];             //为第1行分配5列
    numfive[1]=new long[6];             //为第2行分配6列
    numfive[2]=new long[7];             //为第3行分配7列
    numfive[3]=new long[8];             //为第4行分配8列
    numfive[4]=new long[9];             //为第5行分配9列
    numfive[0][4]=10000000000L;         //1行5列=10000000000
    numfive[1][5]=20000000000L;         //2行6列=20000000000
    numfive[2][6]=30000000000L;         //3行7列=30000000000
    numfive[3][7]=40000000000L;         //4行8列=40000000000
    numfive[4][8]=50000000000L;         //5行9列=50000000000
    System.out.println(numfive[0][4]); //打印换行输出喽
    System.out.println(numfive[1][5]);
    System.out.println(numfive[2][6]);
    System.out.println(numfive[3][7]);
    System.out.println(numfive[4][8]);
    System.out.println(numfive[4][7]); //打印输出一个没有定义数组元素的数组 java会自动将他初始化值为0
    }
    }
    //定义二维数组写法3   定义的同时分配空间大小
    class numfour
    {
    public static void main(String[] args)
    {
       short[][] numfour=new short[5][8]; //定义一个short类型的数组同时为它分配5行8列的空间大小
       numfour[0][7]=10;
       numfour[1][6]=20;
       numfour[2][5]=30;
       numfour[3][4]=40;
       numfour[4][3]=50;
       System.out.println(numfour[0][7]);
       System.out.println(numfour[1][6]);
       System.out.println(numfour[2][5]);
       System.out.println(numfour[3][4]);
       System.out.println(numfour[4][3]);
    }
    }
  • 相关阅读:
    Spring Boot确保Web应用安全(登陆认证)
    ubuntu kylin 18.04安装docker笔记
    Spring Boot项目中MyBatis连接DB2和MySQL数据库返回结果中一些字符消失——debug笔记
    node.js运行内存堆溢出的解决办法
    [转]Maven项目读取src.main.resources下的文件
    Linux下切换用户根目录的指令
    Example config file /etc/vsftpd.conf
    一个可以让vsftpd启动系统用户登陆ftp的例子
    [转]将西部数据 My Passport Wireless 移动存储连接到任何支持的云存储上
    Java连接阿里云HBase示例
  • 原文地址:https://www.cnblogs.com/scodong/p/4819566.html
Copyright © 2011-2022 走看看