简体   繁体   English

TestNG失败时重新运行测试,而不运行BeforeClass AfterClass方法

[英]TestNG Re run test on failure, not running BeforeClass AfterClass methods

I implemented logic that re runs a failed TestNG test class from the following link: 我实现了从以下链接重新运行失败的TestNG测试类的逻辑:

https://martinholladay.wordpress.com/2013/11/17/webdriver-2-0-automatically-retry-failed-tests/ https://martinholladay.wordpress.com/2013/11/17/webdriver-2-0-automatically-retry-failed-tests/

Unfortunately, it runs the method with the "Test" annotation, and not running the BeforeClass (@BeforeClass) and AfterClass (@AfterClass) methods. 不幸的是,它运行带有“ Test”注释的方法,而不运行BeforeClass(@BeforeClass)和AfterClass(@AfterClass)方法。 I tried looking into setDependsOnMethods and getDependsOnMethods methods of ITestAnnotations to no avail. 我试图研究ITestAnnotations的setDependsOnMethods和getDependsOnMethods方法,但无济于事。

Does anybody know how to get the listener class to run BeforeClass and AfterClass methods as well? 有人知道如何让侦听器类也运行BeforeClass和AfterClass方法吗?

public class RetryListener implements IAnnotationTransformer {
    public void transform(ITestAnnotation annotation, Class testClass,
            Constructor testConstructor, Method testMethod) {
        IRetryAnalyzer retry = annotation.getRetryAnalyzer();
        if (retry == null) {
            annotation.setRetryAnalyzer(Retry.class);
        }
    }
}

//The test begins here....

@BeforeClass(alwaysRun = true)
@Parameters("Environment")
public void BeforeClass(String sEnv) throws Exception {
    WebDriver driver = new FirefoxDriver();
    driver.get("www.google.com");

}

@Test
public void TestMethod() {
    //Some test...
}

@AfterClass(alwaysRun = true)
public void AfterClass() {
    driver.quit();
}

TestNG invokes only failed @Test methods. TestNG仅调用失败的@Test方法。 You can see implementation here https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java#L1408 您可以在此处查看实现https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/internal/Invoker.java#L1408

So no, you can't invoke @BeforeClass and @AfterClass in RetryListener again. 因此,不能,您不能再次在RetryListener中调用@BeforeClass@AfterClass

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TestNG 重试类不运行 @BeforeClass 也不 @AfterClass 方法 - TestNG retry class doesn't run @BeforeClass nor @AfterClass methods 如何使用TestNG在循环中运行@beforeclass @test和@Afterclass案例 - How to run @beforeclass @test and @Afterclass cases in a loop using TestNG 如何忽略/跳过包含少量测试方法和BeforeClass&AfterClass方法的完整testng类 - How to ignore/skip complete testng class containing few test methods & BeforeClass & AfterClass methods 将参数传递给@BeforeClass和@AfterClass方法 - Passing params to @BeforeClass and @AfterClass methods 魅力-我想在Report中更改@BeforeClass和@AfterClass方法的标题(我正在使用TestNG) - Allure - i want to change the title of @BeforeClass and @AfterClass methods in Report(I am using TestNG) TestNG @BeforeClass初始化代码未在Test之前运行 - TestNG @BeforeClass initialization code not running before Test 运行两次Testng的beforeClass测试方法 - beforeClass test method running twice Testng 如何通过testNG.xml文件将参数传递给@BeforeClass和@AfterClass方法 - How to pass parameters to @BeforeClass & @AfterClass methods through testNG.xml file 每次测试之前和之后调用@BeforeClass和@AfterClass - @BeforeClass and @AfterClass called before and after each test 想要使用共享的@ BeforeClass / @ AfterClass和Spring App Context运行许多jUnit测试类 - Want to run many jUnit test classes with a shared @BeforeClass/@AfterClass and Spring App Context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM