有条件地跳过TestNG测试

编程入门 行业动态 更新时间:2024-10-26 15:24:20
本文介绍了有条件地跳过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测试

本文发布于:2023-11-25 03:53:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628213.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有条件   跳过   测试   TestNG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!