qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問(wèn) http://qaseven.github.io/

          關(guān)于使用TestNG的retry問(wèn)題

          總體是利用TestNG里面的IRetryAnalyzer、TestListenerAdapter接口來(lái)實(shí)現(xiàn)相關(guān)問(wèn)題
            1、定義一個(gè)自己的retryanalyzer
          import org.testng.ITestResult;
          import org.testng.util.RetryAnalyzerCount;
          //這里集成自抽象類(lèi)RetryAnalyzerCount,該抽象類(lèi)實(shí)現(xiàn)了IRetryAnalyzer
          public class TestRetryAnalyzer extends RetryAnalyzerCount{
          public TestRetryAnalyzer(){
          setCount(1);
          }
          @Override
          public boolean retryMethod(ITestResult arg0) {
          // TODO Auto-generated method stub
          return true;
          }
          }
            2、定義自己的監(jiān)聽(tīng)器,集成自TestListenerAdapter
          import java.util.ArrayList;
          import java.util.Collections;
          import java.util.List;
          import org.testng.IResultMap;
          import org.testng.ITestContext;
          import org.testng.ITestResult;
          import org.testng.Reporter;
          import org.testng.TestListenerAdapter;
          import org.testng.ITestNGMethod;
          import org.testng.collections.Lists;
          import org.testng.collections.Objects;
          public class RetryTestListener extends TestListenerAdapter {
          private List<ITestNGMethod> m_allTestMethods =
          Collections.synchronizedList(Lists.<ITestNGMethod>newArrayList());
          private List<ITestResult> m_passedTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList());
          private List<ITestResult> m_failedTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList());
          private List<ITestResult> m_skippedTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList());
          private List<ITestResult> m_failedButWSPerTests = Collections.synchronizedList(Lists.<ITestResult>newArrayList());
          private List<ITestContext> m_testContexts= Collections.synchronizedList(new ArrayList<ITestContext>());
          private List<ITestResult> m_failedConfs= Collections.synchronizedList(Lists.<ITestResult>newArrayList());
          private List<ITestResult> m_skippedConfs= Collections.synchronizedList(Lists.<ITestResult>newArrayList());
          private List<ITestResult> m_passedConfs= Collections.synchronizedList(Lists.<ITestResult>newArrayList());
          public synchronized void onTestFailure(ITestResult arg0) {
          m_allTestMethods.add(arg0.getMethod());
          m_failedTests.add(arg0);
          }
          @Override
          public void onFinish(ITestContext context) {
          for(int i=0;i<context.getAllTestMethods().length;i++){
          System.out.println("~~~~~~~~~~"+context.getAllTestMethods()[i].getCurrentInvocationCount());
          if(context.getAllTestMethods()[i].getCurrentInvocationCount()==2){
          System.out.println("~~~~~~~~~~~~~~~~~"+context.getAllTestMethods()[i].getParameterInvocationCount());
          System.out.println(context.getAllTestMethods()[i].ignoreMissingDependencies());
          if
          (context.getFailedTests().getResults(context.getAllTestMethods()[i]).size()
          == 2 ||
          context.getPassedTests().getResults(context.getAllTestMethods()[i]).size()
          == 1){
          context.getFailedTests().removeResult(context.getAllTestMethods()[i]);
          }
          }
          }
          }
          ...
          }

          posted on 2014-11-04 10:22 順其自然EVO 閱讀(792) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 測(cè)試學(xué)習(xí)專(zhuān)欄

          <2014年11月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類(lèi)

          隨筆檔案

          文章分類(lèi)

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 威信县| 肃北| 义乌市| 宜川县| 大姚县| 南郑县| 绥滨县| 全州县| 达孜县| 固阳县| 怀仁县| 寻乌县| 怀远县| 兴山县| 海阳市| 沂源县| 宜昌市| 泰宁县| 旌德县| 伊通| 洛南县| 苍溪县| 崇明县| 海宁市| 翼城县| 仁怀市| 承德市| 武冈市| 和林格尔县| 乡宁县| 保德县| 临沧市| 鹤岗市| 临沂市| 门头沟区| 恩施市| 吉隆县| 锡林郭勒盟| 罗田县| 紫阳县| 隆林|