2014-10-07 115 views

回答

2

您可以使用IInvokedMethodListener

重寫接口的兩種方法。在afterInvocation後,檢查結果並可能添加到Map<method, failureCount>

在beforeInvocation中,檢查如果failureCount> 4然後拋出SkipException,將導致剩餘的調用被跳過。

喜歡的東西:

static Map<String, Integer> methodFailCount = new HashMap<String, Integer>(); 
    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { 

     if(methodFailCount.get(method.getTestMethod().getMethodName())!= null && methodFailCount.get(method.getTestMethod().getMethodName()) > 4) 
      throw new SkipException("Skipped due to failure count > 4"); 
    } 

    public void afterInvocation(IInvokedMethod method, ITestResult testResult) { 
     if(testResult.getStatus() == TestResult.FAILURE){ 
      if(methodFailCount.get(method.getTestMethod().getMethodName()) == null) 
       methodFailCount.put(method.getTestMethod().getMethodName(),1); 
      else{ 
       methodFailCount.put(method.getTestMethod().getMethodName(), 
         methodFailCount.get(method.getTestMethod().getMethodName())+1); 
      } 

     } 

    } 
+0

好極了!這幫助了很多 – javanoob 2014-10-10 04:24:17

相關問題