zoukankan      html  css  js  c++  java
  • testng入门教程13同文件数据驱动

    下面是@DataProvider有name和没有name时

    有name的时候可以引用name 即:@DataProvider(name="testData")---------->@Test(dataProvider="testData")

    package data_driver;
    
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    public class TestDataDriven {
        @DataProvider(name="testData")
        public Object[][] dataProvider(){
            return new Object[][]{{1,2},{2,3},{3,4}};    
        }
        
        
        @Test(dataProvider="testData")
        public void testDataDriven(int a,int b){
            System.out.println("this is :"+(a+b));
        }
    }

    右键----->RunAs----->TestNG test   运行结果如下:

    [TestNG] Running:
      C:UserschenjiaAppDataLocalTemp	estng-eclipse--2116911479	estng-customsuite.xml
    
    this is :3
    this is :5
    this is :7
    PASSED: testDataDriven(1, 2)
    PASSED: testDataDriven(2, 3)
    PASSED: testDataDriven(3, 4)
    
    ===============================================
        Default test
        Tests run: 3, Failures: 0, Skips: 0
    ===============================================
    
    
    ===============================================
    Default suite
    Total tests run: 3, Failures: 0, Skips: 0
    ===============================================

    没有name的时候可以引用方法名即:

    package data_driver;
    
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    public class TestDataDriven{
        @DataProvider
        public Object[][] dataprovider(){
            return new Object[][]{{1,2},{2,3},{3,4},{4,5},{5,6}};
            
        }
        
        @Test(dataProvider="dataprovider")
        public void testDataDriven(int a, int b){
            System.out.println("this is :"+ (a + b));
        }    
    }

    右键----->RunAs----->TestNG test   运行结果如下:

    [TestNG] Running:
      C:UserschenjiaAppDataLocalTemp	estng-eclipse-1345547329	estng-customsuite.xml
    
    this is :3
    this is :5
    this is :7
    this is :9
    this is :11
    PASSED: testDataDriven(1, 2)
    PASSED: testDataDriven(2, 3)
    PASSED: testDataDriven(3, 4)
    PASSED: testDataDriven(4, 5)
    PASSED: testDataDriven(5, 6)
    
    ===============================================
        Default test
        Tests run: 5, Failures: 0, Skips: 0
    ===============================================
    
    
    ===============================================
    Default suite
    Total tests run: 5, Failures: 0, Skips: 0
    ===============================================
  • 相关阅读:
    非正式介绍Python(二)
    用js采集网页数据并插入数据库最快的方法
    一张图轻松记住PHP的*类*以及private和protected的区别
    从php到浏览器的缓存机制,不得不看!
    webpack 兼容低版本浏览器,转换ES6 ES7语法
    DEDE织梦 后台特别卡,有时响应超时的解决办法
    vue iview Select bug,在低版本浏览器中报错
    mysql_connect 等待时间长,修改连接地址为127.0.0.1即可
    看完这篇文章才对【GIT】有了大彻大悟的认识
    一次请求对多条数据进行排序的算法(二)
  • 原文地址:https://www.cnblogs.com/111testing/p/6204560.html
Copyright © 2011-2022 走看看