zoukankan      html  css  js  c++  java
  • @DataProvider ITestContext 参数

     1 package roger.testng;
     2 
     3 import java.util.Random;
     4 
     5 import org.testng.ITestContext;
     6 import org.testng.annotations.DataProvider;
     7 import org.testng.annotations.Test;
     8 
     9 /*
    10  *  数据提供者在方法签名中声明了一个 ITestContext 类型的参数
    11  *  testng 会将当前的测试上下文设置给它
    12  *  
    13  */
    14 public class TestDataProviderITestContext {
    15     @DataProvider
    16     public Object[][] randomIntegers(ITestContext context) {
    17         String[] groups= context.getIncludedGroups();
    18         int size = 2;
    19         for (String group : groups) {
    20             System.out.println("--------------" + group);
    21             if (group.equals("function-test")) {
    22                 size = 10;
    23                 break;
    24             }
    25         }
    26         
    27         Object[][] result = new Object[size][];
    28         Random r = new Random();
    29         for (int i = 0; i < size; i++) {
    30             result[i] = new Object[] {new Integer(r.nextInt())};
    31         }
    32         
    33         return result;
    34     }
    35     
    36     // 如果在 unite-test 组中执行, 将返回2个随机整数构成数组;
    37     // 如果在 function-test 组中执行, 将返回 10 个随机整数构成数组
    38     @Test(dataProvider = "randomIntegers", groups = {"unit-test", "function-test"})
    39     public void random(Integer n) {
    40         System.out.println(n);
    41     }
    42     
    43 }

    通过 testng.xml 指定运行 unite-test 组还是 function-test 组。

  • 相关阅读:
    用算法合并数组
    Redis各个数据类型的使用场景
    seesion工作原理
    自删除道指令程序
    uva 1335
    《生活在Linux中》之:使用Bash就是使用Emacs
    手动配置S2SH三大框架报错(三)
    数据和C
    IOS之【地图MapKit】
    我工作这几年(五)-- Android学习4.5月总结(一)
  • 原文地址:https://www.cnblogs.com/Roger1227/p/3851159.html
Copyright © 2011-2022 走看看