spoon+robotium+jenkins进行自动化持续回归测试

  1. logDebug(debug, “About to actually run tests for [%s]”, serial);  
  2. junitReport = FileUtils.getFile(output, JUNIT_DIR, serial + “_” + i + “_” +“.xml”);  
  3. runner = new RemoteAndroidTestRunner(testPackage, testRunner, device);  
  4. runner.setCoverage(true);//注:set为true后,被测应用打包时需要插桩才能生成ec代码覆盖率统计文件  
  5. runner.addInstrumentationArg(“coverageFile”“/sdcard/robotium/spoon” + i + “.ec”);  
  6. runner.setMaxtimeToOutputResponse(adbTimeout);  
  1. @Override  
  2.    protected void runTest() throws Throwable {  
  3.       
  4.     String testMethodName = getName();  
  5.     String currentTestClass = getClass().getName();  
  6.     LogUtils.logD(TAG, “currentTestClass:” + currentTestClass);  
  7.     boolean isScreenShot = true;  
  8.     boolean isScreenShotWhenPass = false;  
  9.     long startTime = 0;  
  10.     long endTime = 0;  
  11.     Holo holo = new Holo(getInstrumentation(), getActivity());//这里的holo是经过增删后的robotium,理解为solo即可  
  12.     String currentActivity = getActivity().getClass().getSimpleName();  
  13.     LogUtils.logD(TAG, “currentActivity:” + currentActivity);  
  14.     Method method = getClass().getMethod(getName(), (Class[]) null);             
  15.       
  16.     int retrytime = 3;  
  17.     if (method.isAnnotationPresent(RetryTest.class)) {  
  18.         retrytime = method.getAnnotation(RetryTest.class).retrytime();  
  19.         isScreenShot = method.getAnnotation(RetryTest.class).isScreenShot();  
  20.        }   
  21.     LogUtils.logD(TAG, “isScreenShot:” + isScreenShot);  
  22.       
  23.     int runCount = 0;  
  24.       
  25.     do {  
  26.         LogUtils.logD(TAG, “runCount:” + runCount);  
  27.         try {  
  28.             holo.goBackToActivity(currentActivity);  
  29.             if(runCount > 0){//当用例第一遍执行未通过后,开启截图序列,至于要截多少张图,可以根据实际情况来设计  
  30.                 holo.stopScreenshotSequence();  
  31.                 holo.startScreenshotSequence(endTime, 5, testMethodName, currentTestClass);  
  32.             }  
  33.             startTime = SystemClock.uptimeMillis();  
  34.             super.runTest();  
  35.             endTime = SystemClock.uptimeMillis() – startTime;  
  36.             LogUtils.logD(TAG, “run test” + testMethodName + “,testcase pass with time cost:” + endTime);  
  37.             if(isScreenShotWhenPass){  
  38.                 holo.takeSpoonScreenShot(testMethodName,currentTestClass,testMethodName,DEFAULT_QUALITY);  
  39.             }  
  40.             if(holo != null){  
  41.                 holo = null;  
  42.             }  
  43.               
  44.             break;                
  45.         } catch (Throwable e) {               
  46.             if(retrytime>1 && runCount<retrytime-1){  
  47.                 runCount++;  
  48.                 endTime = SystemClock.uptimeMillis() – startTime;  
  49.                 LogUtils.logD(TAG, “run test” + testMethodName + “,testcase failed with time cost:” + endTime);  
  50.       

    声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2015年2月10日
下一篇 2015年2月10日

相关推荐