zoukankan      html  css  js  c++  java
  • TestNG(十三) 参数化测试(DataProvider)

    package com.course.testng.Parameter;
    
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    public class ProviderData {
        @Test(dataProvider = "data")
        public void testProviderData(String name,int age){
            System.out.println("name = "+ name +";  age = "+age);
        }
    
        @DataProvider(name = "data")
        public Object[][] providerData(){
            Object[][] para = new Object[][]{
                    {"萨顶顶",26},
                    {"周杰伦",33},
                    {"阿三啊",16}
            };
            return para;
        }
    }



    package com.course.testng.Parameter;
    
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    import java.lang.reflect.Method;
    
    public class ProviderData {
        @Test(dataProvider = "data")
        public void testProviderData(String name,int age){
            System.out.println("name = "+ name +";  age = "+age);
        }
    
        @DataProvider(name = "data")
        public Object[][] providerData(){
            Object[][] para = new Object[][]{
                    {"萨顶顶",26},
                    {"周杰伦",33},
                    {"阿三啊",16}
            };
            return para;
        }
    
        @Test(dataProvider = "methodData")
        public void test1(String name,int age){
            System.out.println("test1方法 name = "+name+"; age = "+age);
        }
    
        @Test(dataProvider = "methodData")
        public void test2(String name,int age){
            System.out.println("test2方法 name = "+name+"; age = "+age");
        }
        @DataProvider(name = "methodData")
        public Object[][] methodDataTest(Method method){
            Object[][] result = null;
            if (method.getName().equals("test1")){
                result = new Object[][]{
                        {"张张",20},
                        {"五五",25},
                        {"嘻嘻",18}
                };
            }else if (method.getName().equals("test2")){
                result = new Object[][]{
                        {"六六",17},
                        {"七七",21},
                        {"霞霞",28}
                };
            }
            return result;
        }
    }

  • 相关阅读:
    【2021-08-25】连岳摘抄
    【2021-08-24】对意义的过度扭曲
    【2021-08-23】枕边语
    【2021-08-22】连岳摘抄
    【2021-08-21】旅历尚浅
    【2021-08-20】做事情,等对应好角色去思考
    索引缓冲对象(EBO或IBO )的理解
    vao, vbo的一点拙见
    兔队线段树
    「具体数学」二:和式
  • 原文地址:https://www.cnblogs.com/dwdw/p/11420175.html
Copyright © 2011-2022 走看看