• (三)利用@DataProvider传递参数


    具体实现如下:

    @DataProvider(name="couponListData")
        public Object[][] couponListData(){
            //自己定义Object[][]值
            List<ListManage> couponManageList = ExcelUtil.simpleRead(AdminFileName.CouponManagePath, ListManage.class);
            Object[][] o = new Object[couponManageList.size()][];
            for(int i=0; i<couponManageList.size();i++){
                JSONObject jsonObject = new JSONObject(true);
                Object[] objects = new Object[3];
                jsonObject.put("condition",couponManageList.get(i).getCondition());//code:券码编号,name:券码名字,customer_name:采购用户
                jsonObject.put("content",couponManageList.get(i).getContent());
                jsonObject.put("current_page",couponManageList.get(i).getCurrentPage());
                jsonObject.put("page_size",couponManageList.get(i).getPageSize());
                objects[0] = couponManageList.get(i).getCode();
                objects[1] = couponManageList.get(i).getAccountInformation();
                objects[2] = jsonObject;
                o[i] = objects;
    
            }
            return o;
        }
    
    @Test(dataProvider = "couponListData")
        public void couponList(String code,String accountInformation,JSONObject data) throws Exception{
        
    }            
    

    不同类的用法:

    数据驱动类DataProviderDemo .java

    package com.yck.demo.data;
     
    import org.testng.annotations.DataProvider;
     
    import com.yck.demo.entity.TestDataVo;
    import com.yck.demo.utils.MybatisUtil;
     
    public class DataProviderDemo {
     
    	@DataProvider(name = "providerName")
    	public TestDataVo[][] demo() {
    		String statement = "mapper.TestDataMapper.getdataByCaseName";
    		TestDataVo vo1 = MybatisUtil.excuteSelect(statement, "1");
    		TestDataVo vo2 = MybatisUtil.excuteSelect(statement, "2");
    		TestDataVo vo3 = MybatisUtil.excuteSelect(statement, "3");
    		TestDataVo[][] dataVo = {{vo1},{vo2},{vo3}};
    		return dataVo;
    		
    	}
     
    }
    

    测试用例类:

    package com.yck.demo.testcase;
     
    import java.io.IOException;
    import java.io.InputStream;
     
    import org.apache.ibatis.io.Resources;
    import org.apache.ibatis.session.SqlSession;
    import org.apache.ibatis.session.SqlSessionFactory;
    import org.apache.ibatis.session.SqlSessionFactoryBuilder;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
     
    import com.yck.demo.entity.TestDataVo;
     
    public class DemoTestCase {
     
    	
    	
    	@Test(dataProvider= "providerName",dataProviderClass= com.yck.demo.data.DataProviderDemo.class)
    	public void test(TestDataVo vo) {
    		System.out.println(vo.getActual());
    	}
    }
    

      

      

      

  • 相关阅读:
    使用yum命令报错
    CentOS6.8安装Python3.6.3
    解决 linux 下安装 node 报: command not found
    Python的pip源切换为国内阿里云镜像
    开源Java加密工具Jasypt 1.4发布
    JavaFX对Java开发者到底意味着什么?
    16 个印象深刻的 HTML5/CSS3/JavaScript 体验
    高效的Java异常处理
    Java开发的学习过历程
    Java中23种设计模式详解
  • 原文地址:https://www.cnblogs.com/lvchengda/p/13044422.html
Copyright © 2020-2023  润新知