【问题标题】:TestNg @afterclass isn't invoked if there is disabled test in a class如果类中有禁用测试,则不会调用 TestNg @afterclass
【发布时间】:2011-10-21 11:45:25
【问题描述】:

我正在使用 testng+webdriver 进行自动化测试。还有一个问题是@AfterClass 注解没有像我预期的那样工作。

我有以下测试类:

    public class WorkspaceTest{
        @BeforeClass
        public void init(){
            //Initialization steps
        }

        @Test
        public void testMethod1{...}

        @Test
        public void testMethod2{...}

        @Test(enabled=false)
        public void testMethod3{...}

        @AfterClass(alwaysRun=true)
        public void tearDown{
            //finalizing steps 
        }

}

如果启用了所有测试方法 - tearDown 方法工作正常, 但如果其中一项测试被禁用 - 我什至没有达到 tearDown 方法的断点。

@AfterClass 注释的预期行为吗?还是我做错了什么?

Testng version: 6.1.1
Webdriver 2.5.0
Java 1.6.0_26

【问题讨论】:

  • 我在 IntelliJ 中运行 TestNG 测试时遇到了同样的错误,但当我通过 Gradle 运行测试时,它正确调用了 @AfterClass(即使一种方法是 enabled=false)。

标签: java selenium webdriver testng


【解决方案1】:

它对我有用:

tearDown
PASSED: testMethod1
PASSED: testMethod2

===============================================
    Test1
    Tests run: 2, Failures: 0, Skips: 0
===============================================

这是我使用的来源:

public class A {
      @BeforeClass
      public void init(){
          //Initialization steps
      }

      @Test
      public void testMethod1() {}

      @Test
      public void testMethod2() {}

      @Test(enabled=false)
      public void testMethod3() {}

      @AfterClass(alwaysRun=true)
      public void tearDown() {
        System.out.println("tearDown");
      }

}

【讨论】:

  • 感谢您的宝贵时间!看起来我本地化了问题。 Eclipse testng 插件存在一些问题。同样的测试在 IntelliJIdea 上运行良好
  • 您可以通过电子邮件将您的发现发送给 testng-users 列表吗?很高兴看看是不是 TestNG Eclipse 插件的问题。
【解决方案2】:

如果你使用标准的junit @AfterClass 应该在public static void 方法上注解,例如:

@AfterClass
public static void logout() {}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    相关资源
    最近更新 更多