- logDebug(debug, “About to actually run tests for [%s]”, serial);
- junitReport = FileUtils.getFile(output, JUNIT_DIR, serial + “_” + i + “_” +“.xml”);
- runner = new RemoteAndroidTestRunner(testPackage, testRunner, device);
- runner.setCoverage(true);//注:set为true后,被测应用打包时需要插桩才能生成ec代码覆盖率统计文件
- runner.addInstrumentationArg(“coverageFile”, “/sdcard/robotium/spoon” + i + “.ec”);
- runner.setMaxtimeToOutputResponse(adbTimeout);
- @Override
- protected void runTest() throws Throwable {
- String testMethodName = getName();
- String currentTestClass = getClass().getName();
- LogUtils.logD(TAG, “currentTestClass:” + currentTestClass);
- boolean isScreenShot = true;
- boolean isScreenShotWhenPass = false;
- long startTime = 0;
- long endTime = 0;
- Holo holo = new Holo(getInstrumentation(), getActivity());//这里的holo是经过增删后的robotium,理解为solo即可
- String currentActivity = getActivity().getClass().getSimpleName();
- LogUtils.logD(TAG, “currentActivity:” + currentActivity);
- Method method = getClass().getMethod(getName(), (Class[]) null);
- int retrytime = 3;
- if (method.isAnnotationPresent(RetryTest.class)) {
- retrytime = method.getAnnotation(RetryTest.class).retrytime();
- isScreenShot = method.getAnnotation(RetryTest.class).isScreenShot();
- }
- LogUtils.logD(TAG, “isScreenShot:” + isScreenShot);
- int runCount = 0;
- do {
- LogUtils.logD(TAG, “runCount:” + runCount);
- try {
- holo.goBackToActivity(currentActivity);
- if(runCount > 0){//当用例第一遍执行未通过后,开启截图序列,至于要截多少张图,可以根据实际情况来设计
- holo.stopScreenshotSequence();
- holo.startScreenshotSequence(endTime, 5, testMethodName, currentTestClass);
- }
- startTime = SystemClock.uptimeMillis();
- super.runTest();
- endTime = SystemClock.uptimeMillis() – startTime;
- LogUtils.logD(TAG, “run test” + testMethodName + “,testcase pass with time cost:” + endTime);
- if(isScreenShotWhenPass){
- holo.takeSpoonScreenShot(testMethodName,currentTestClass,testMethodName,DEFAULT_QUALITY);
- }
- if(holo != null){
- holo = null;
- }
- break;
- } catch (Throwable e) {
- if(retrytime>1 && runCount<retrytime-1){
- runCount++;
- endTime = SystemClock.uptimeMillis() – startTime;
- LogUtils.logD(TAG, “run test” + testMethodName + “,testcase failed with time cost:” + endTime);
-
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!