如果在testNG之前/之后的方法失败或跳过,重试将不会继续?

时间:2017-05-24 05:51:36

标签: java testng

我通过实现IRetryAnalyzer来编写重试机制。刚发现,如果beforemethod / aftermethod出现异常,重试机制将不起作用,是作为设计还是我的代码问题?

   public class MyRetryAnalyzer implements IRetryAnalyzer {
  public static int MAX_RETRY_COUNT = 3;

  // to avoid the thread safe issue, use the AtomicInteger class, instead of Integer
  AtomicInteger count = new AtomicInteger(MAX_RETRY_COUNT);

  public boolean isRetryAvailable() {
    return (count.intValue() > 0);
  }

  /**
   * retry a failed test
   *
   * @param ITestResult result - the test result of current test case
   * 
   * @return Returns true if the test method has to be retried, false otherwise.
   * 
   * @author Fiona Zhang
   */

  @Override
  public boolean retry(ITestResult result) {
    boolean retry = false;
    System.out.println("result status is : ------------------------- "+result.getStatus());
    if (isRetryAvailable()) {
      System.out.println("Going to retry test case: " + result.getMethod() + ", "
          + (MAX_RETRY_COUNT - count.intValue() + 1) + " out of " + MAX_RETRY_COUNT);
      retry = true;
      // --count
      count.decrementAndGet();
    }
    return retry;
  }
}

0 个答案:

没有答案