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
    ===============================================
  • 相关阅读:
    jQuery实现AJAX定时局部页面刷新
    设为首页,收藏本站
    Js 实现页面跳转的几种方式
    js Javascript刷新页面的几种方法
    js 返回上一页或上几页
    ASP.NET, IE6下URL中文乱码问题 ASP.NET程序,当URL后缀包含奇数个中文字符
    SQL数据库。按年,月,日查询
    20155324 2016-2017-2 《Java程序设计》第6周学习总结
    20155324 2016-2017-2 《Java程序设计》第5周学习总结
    20155324 2016-2017-2 《Java程序设计》第4周学习总结
  • 原文地址:https://www.cnblogs.com/111testing/p/6204560.html
Copyright © 2011-2022 走看看