是否@Test(启用= FALSE)工作TestNG中的一类? [英] Does @Test(enabled = false) work for a class in TestNG?

查看:498
本文介绍了是否@Test(启用= FALSE)工作TestNG中的一类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从TestNG的文档,我可以看到(启用= FALSE)可以应用于类或方法。但似乎当应用于方法它才有效。

From the TestNG doc I can see that (enabled = false) can be applied to a class or method. But it seems it only works when applied to a method.

有人看到了同样的,找到了解决办法?

Anybody seen the same, found a solution?

我的方式运行在ItelliJ IDEA 7.0的测试。

I'm running tests in ItelliJ IDEA 7.0 by the way.

推荐答案

这似乎为我工作:

@Test(enabled = false)
public class B {    
  public void btest1() {
    System.out.println("B.btest1");
  }
}

结果:

===============================================
SingleSuite
Total tests run: 0, Failures: 0, Skips: 0
===============================================

更改假为真:

B.btest1

===============================================
SingleSuite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

下面是可能被绊倒你(很难说,因为你没有提供任何code):

Here is what might be tripping you (hard to tell since you didn't provide any code):

@Test(enabled = false)
public class B {
 @Test
 public void btest1() {
   System.out.println("B.btest1");
 }
}

此案件将因为重复的方法 @Test 注释运行测试,你也覆盖已启用属性为默认值,即真正

This case will run the test because by repeating the @Test annotation on the method, you are also overriding the enabled attribute to its default value, which is true.

解决方案是重申启用=假在方法级别:

The solution is to reiterate enabled=false at the method level:

@Test(enabled = false)
public class B {

 @Test(enabled = false)
 public void btest1() {
   System.out.println("B.btest1");
  }
}

我知道这有点违反直觉,但它是必要的,以便在路上方法注释可以覆盖类注解是一致的。

I'm aware it's a bit counterintuitive but it's necessary in order to be consistent in the way method annotations can override class annotations.

这篇关于是否@Test(启用= FALSE)工作TestNG中的一类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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