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
    ===============================================
  • 相关阅读:
    flash 异性窗体
    ASCⅡ 表 关键字符
    VC 中显示位图的步骤
    输出电脑的所有Mac地址
    const char* 和 char* const
    C# 生成PDF
    vc6显示行号
    纪念一下。
    MII接口全家福
    Virtex6 GTX设计总结:预加重、均衡、输出振幅的值
  • 原文地址:https://www.cnblogs.com/111testing/p/6204560.html
Copyright © 2011-2022 走看看