有条件地跳过TestNG测试 [英] Conditional skipping of TestNG tests

查看:242
本文介绍了有条件地跳过TestNG测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对TestNG注释没有多少经验,但我正在尝试使用TestNG框架和零售网站的POM设计模式构建测试套件。我打算使用数据驱动的方法。我的计划是通过excel驱动我的测试场景,而不是使用testng.xml。

I don't have much experience with TestNG annotations, however I am trying to build a test suite using TestNG framework and POM design pattern for a retail website. I am planning to use a data driven approach. My plan is to drive my test scenarios through excel and not using testng.xml.

例如,我将拥有多个测试套件,这将是各种类文件在包名称TestSuite下。 TestSuite名称将列在excel中,用户可以通过将运行模式更改为TRUE / FALSE来设置测试套件的运行模式。
这里我打算实施条件检查以查看Run模式是否为FALSE并因此跳过testsuite,即testsuite类。

For example I will be having number of testsuites, which will be nothing but various class files under a package name TestSuite. TestSuite names will be listed in an excel and user will be allowed to set the run mode of the testsuite by changing the run mode to TRUE/FALSE. Here I am planning to implement a condition check to see if the Run mode is FALSE and accordingly skip the testsuite, i.e. the testsuite class.

我们有没有使用TestNG实现相同的任何直接方法或请用一个小例子建议任何解决方案。

Do we have any direct method to achieve the same using TestNG or please suggest any solution for the same with a small example.

推荐答案

你可以使用TestNG的注释变换器设置已禁用 @Test 注释的属性为true或false。

You can use TestNG's annotation transformer to set the disabled property of a @Test annotation to true or false.

示例:

public class MyTransformer implements IAnnotationTransformer {
    public void transform(ITest annotation, Class testClass,
        Constructor testConstructor, Method testMethod){

        if (isTestDisabled(testMethod.getName()))) {
            annotation.setEnabled(false);
        }
    }

    public boolean isTestDisabled(String testName){
       // Do whatever you like here to determine if test is disabled or not
    }
}

这篇关于有条件地跳过TestNG测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆