如何根据条件禁用TestNG的测试 [英] How to disable testng test based on a condition

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

问题描述

有没有目前的方式来基于条件的停用TestNG的测试

Is there currently a way to disable Testng test based on a condition

我知道你可以禁用当前测试如此TestNG中:

I know you can currently disable test as so in Testng:

@Test(enabled=false, group={"blah"})
public void testCurrency(){
...
}

我会想禁用基于一个条件相同的测试,但不知道怎么办。事情是这样的:

I will like to disable the same test based on a condition but dont know how. something Like this:

@Test(enabled={isUk() ? false : true), group={"blah"})
public void testCurrency(){
...
}

任何人有这是否可能不是一个线索。

Anyone has a clue on whether this is possible or not.

推荐答案

您有两种选择:

  • Implement an annotation transformer.
  • Use BeanShell.

您注释变压器将测试的条件,然后覆盖@Test标注添加已启用=假的属性,如果条件不满足。

Your annotation transformer would test the condition and then override the @Test annotation to add the attribute "enabled=false" if the condition is not satisfied.

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

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