栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如果是两个组的成员,是否可以为TestNG设置条件以运行测试?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如果是两个组的成员,是否可以为TestNG设置条件以运行测试?

您可以创建实现IMethodInterceptor接口的侦听器。这将使您能够从@Test访问组列表,并根据需要管理“测试要执行的列表”。同时,ITestContext参数允许您从testNg
xml访问数据。因此,您可以将组设置为以默认的testNg方式运行(合适的xml文件);但根据您实现的算法运行它们。就像是:

import java.util.ArrayList;import java.util.Arrays;import java.util.List;import org.testng.IMethodInstance;import org.testng.IMethodInterceptor;import org.testng.ITestContext;import org.testng.annotations.Test;public class Interceptor implements IMethodInterceptor{    @Override    public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context)    {        int methCount = methods.size();        List<IMethodInstance> result = new ArrayList<IMethodInstance>();        for (int i = 0; i < methCount; i++)        { IMethodInstance instns = methods.get(i); List<String> grps = Arrays.asList(instns.getMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class).groups());//get these groups from testng.xml via context method parameter    if (grps.contains("A") && grps.contains("B")) {     result.add(instns); }         }         return result;    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/447861.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号