TestNG如何在继承前测试失败时跳过测试

时间:2016-11-10 13:56:44

标签: java testing testng

我对testNG有点问题。在我的示例代码下面:

abstract class parent {

 abstract void beforeTest();

 @Test
 void test() {
         // some testing
 }
}

class child extends parent {

 @BeforeTest
 void beforeTest() {
      \\some before things
 }
}

问题是如何使这段代码正常工作?所以我想执行beforeTest()方法,如果它失败了测试方法,请跳过。我怎样才能实现这个目标?

1 个答案:

答案 0 :(得分:0)

通常,配置方法会进入parrent,测试类应该扩展parrent。 因此,请尝试将此示例用于测试:

abstract class TestBase {
    @BeforeTest
    public void beforeTest() {
        // do config here 
        // this will run for each of you <test> tag in your testng.xml suite
    }

    @BeforeMethod
    public void beforeMethod() {
        // do some config here 
        // this will run for each method annotated with @Test
    }
}

class SomeTestClass extends TestBase {
    @Test
    public void some_test() {
        // some testing
    }
}