RemoteAndroidTestRunner remoteAndroidTestRunner = new RemoteAndroidTestRunner( parsedInstrumentationPackage, parsedInstrumentationRunner, device ); remoteAndroidTestRunner.setTestPackageName( str ); getLog().info( deviceLogLinePrefix + "Running tests for specified test package: " + str ); .setClassNames( parsedClasses.toArray( new String[ parsedClasses.size() ] ) ); getLog().info( deviceLogLinePrefix + "Running tests for specified test classes/methods: " + parsedClasses ); remoteAndroidTestRunner.addInstrumentationArg( "annotation", annotation ); remoteAndroidTestRunner.addInstrumentationArg( "notAnnotation", annotation ); remoteAndroidTestRunner.setDebug( parsedDebug ); remoteAndroidTestRunner.setCoverage( parsedCoverage ); if ( StringUtils.isNotBlank( parsedCoverageFile ) ) remoteAndroidTestRunner.addInstrumentationArg( "coverageFile", parsedCoverageFile ); remoteAndroidTestRunner.setLogOnly( parsedLogOnly ); remoteAndroidTestRunner.setTestSize( validSize ); remoteAndroidTestRunner.run( testRunListener ); if ( testRunListener.hasFailuresOrErrors() && !testFailSafe )
private LogRecordingTestRunListener queryTestSet(final String testPackage, final String testRunner, final IDevice device) throws Exception { LogRecordingTestRunListener recorder = new LogRecordingTestRunListener(); logDebug(debug, "Querying a list of tests on [%s]", serial); RemoteAndroidTestRunner runner = createConfiguredRunner(testPackage, testRunner, device); runner.addBooleanArg("log", true); runner.run(recorder); return recorder; }
instrumentationInfo.getApplicationPackage(), testPackage, testRunner, device, clearAppDataBeforeEachTest, debug); runner.setMaxTimeToOutputResponse(adbTimeout.toMillis(), TimeUnit.MILLISECONDS); continue; runner.addInstrumentationArg(entry.getKey(), entry.getValue()); runner.setClassName(className); } else { runner.setMethodName(className, methodName); runner.setTestSize(testSize);
RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner( testData.getApplicationId(), testData.getInstrumentationRunner(), runner.addInstrumentationArg(argument.getKey(), argument.getValue()); runner.addInstrumentationArg("coverage", "true"); runner.addInstrumentationArg("coverageFile", coverageFile); runner.setRunName(deviceName); runner.setMaxtimeToOutputResponse(timeoutInMs); runner.run(runListener);
IDevice device = testRunParameters.getDeviceInterface(); RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner( testRunParameters.getTestPackage(), testRunParameters.getTestRunner(), IRemoteAndroidTestRunner.TestSize testSize = testRunParameters.getTestSize(); if (testSize != null) { runner.setTestSize(testSize); runner.setRunName(poolName); runner.setMethodName(testClassName, testMethodName); runner.setMaxtimeToOutputResponse(testRunParameters.getTestOutputTimeout()); runner.setCoverage(true); runner.addInstrumentationArg("coverageFile", RemoteFileManager.getCoverageFileName(new TestIdentifier(testClassName, testMethodName))); runner.addInstrumentationArg("notAnnotation", excludedAnnotation); } else { logger.info("No excluding any test based on annotations"); runner.run(testRunListeners); } catch (ShellCommandUnresponsiveException | TimeoutException e) { logger.warn("Test: " + testClassName + " got stuck. You can increase the timeout in settings if it's too strict");
private void addShardingInstrumentationArgs(RemoteAndroidTestRunner runner) { runner.addInstrumentationArg("numShards", Integer.toString(numShards)); runner.addInstrumentationArg("shardIndex", Integer.toString(shardIndex)); }
private void runTest(Device device, TestCaseEvent testCaseEvent) throws TestFailureException { RemoteAndroidTestRunner androidTestRunner = new RemoteAndroidTestRunner(instrumentationPackage, testRunner, device.getDeviceInterface()); String testClassName = testCaseEvent.getTestClass(); String testMethodName = testCaseEvent.getTestMethod(); androidTestRunner.setMethodName(testClassName, testMethodName); androidTestRunner.setMaxtimeToOutputResponse(Defaults.ADB_MAX_TIME_TO_OUTPUT_RESPONSE); try { PerformanceTestListener performanceTestListener = new LoggingPerformanceTestListener(testCaseEvent, results); performanceTestListener.startOverall(); int iterations = Defaults.ITERATIONS; for (int i = 0; i < iterations; i++) { performanceTestListener.startIteration(); ResultObservingTestRunListener resultObservingTestRunListener = new ResultObservingTestRunListener(); androidTestRunner.run(resultObservingTestRunListener); if (resultObservingTestRunListener.hasFailed()) { throw new TestFailureException(resultObservingTestRunListener.getTestFailure()); } performanceTestListener.endIteration(); } performanceTestListener.endOverall(); } catch (ShellCommandUnresponsiveException | TimeoutException e) { logger.warn("Test: " + testClassName + " got stuck. You can increase the timeout in settings if it's too strict"); } catch (AdbCommandRejectedException | IOException e) { throw new RuntimeException(format("Error while running test %s %s", testClassName, testMethodName), e); } }
logDebug(debug, "Running all tests in a single instrumentation call on [%s]", serial); RemoteAndroidTestRunner runner = createConfiguredRunner(testPackage, testRunner, device); runner.run(listeners); } catch (Exception e) { resultBuilder.addException(e); RemoteAndroidTestRunner runner = createConfiguredRunner(testPackage, testRunner, device); runner.removeInstrumentationArg("package"); runner.setClassName(testGroup); runner.run(listeners); } catch (Exception e) { resultBuilder.addException(e); RemoteAndroidTestRunner runner = createConfiguredRunner(testPackage, testRunner, device); runner.removeInstrumentationArg("package"); runner.setMethodName(test.getClassName(), test.getTestName()); runner.run(listeners); } catch (Exception e) { resultBuilder.addException(e);
@Override public void run(Collection<ITestRunListener> listeners) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { try { if (clearAppDataBeforeEachTest) { logDebug(debug, String.format("Running adb command: %s", clearCommandStr)); remoteDevice.executeShellCommand(clearCommandStr, outputReceiver, MAX_TIMEOUT_MS, MAX_TIME_TO_OUTPUT_RESPONSE_MILLIS, TimeUnit.MILLISECONDS); String output = outputReceiver.getOutput(); if (output == null || !output.contains("Success")) { logError("adb clear command failed with the following output: " + output); } } } catch (IOException | ShellCommandUnresponsiveException | TimeoutException | AdbCommandRejectedException e) { String exceptionName = e.getClass().getSimpleName(); logError(String.format( "%1$s %2$s when running adb 'pm clear' command %3$s on %4$s", exceptionName, e.toString(), getPackageName(), remoteDevice.getName())); throw e; } super.run(listeners); } }
logDebug(debug, "Running all tests in a single instrumentation call on [%s]", serial); RemoteAndroidTestRunner runner = createConfiguredRunner(testPackage, testRunner, device); runner.run(listeners); } catch (Exception e) { result.addException(e); logDebug(debug, "Running %s on [%s]", test, serial); RemoteAndroidTestRunner runner = createConfiguredRunner(testPackage, testRunner, device); runner.removeInstrumentationArg("package"); runner.removeInstrumentationArg("class"); runner.setMethodName(test.getClassName(), test.getTestName()); runner.run(listeners); } catch (Exception e) { result.addException(e);
@Override public void setTestCollection(boolean collect) { if (collect) { // skip test execution setLogOnly(true); // force a timeout for test collection setMaxTimeToOutputResponse(TEST_COLLECTION_TIMEOUT, TimeUnit.MILLISECONDS); if (getApiLevel() < 16 ) { // On older platforms, collecting tests can fail for large volume of tests. // Insert a small delay between each test to prevent this addInstrumentationArg(DELAY_MSEC_ARG_NAME, "15" /* ms */); } } else { setLogOnly(false); // restore timeout to its original set value setMaxTimeToOutputResponse(mMaxTimeToOutputResponse, mMaxTimeUnits); if (getApiLevel() < 16 ) { // remove delay removeInstrumentationArg(DELAY_MSEC_ARG_NAME); } } }
/** * {@inheritDoc} */ public void setDebug(boolean debug) { addBooleanArg(DEBUG_ARG_NAME, debug); }
/** * {@inheritDoc} */ public void setMethodName(String className, String testName) { setClassName(className + METHOD_SEPARATOR + testName); }
RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner( testData.getApplicationId(), testData.getInstrumentationRunner(), runner.addInstrumentationArg(argument.getKey(), argument.getValue()); runner.addInstrumentationArg("coverage", "true"); String coverageFileName = createCoverageFileName(shard); coverageFiles.add(coverageFileName); runner.addInstrumentationArg("coverageFile", coverageFileLocation + coverageFileName); runner.addInstrumentationArg("shardIndex", String.valueOf(shard)); runner.addInstrumentationArg("numShards", String.valueOf(shardProvider.getTotalShards())); runner.setRunName(deviceName); runner.setMaxtimeToOutputResponse(timeoutInMs); runListener = new ShardedTestListener( shard, deviceName, projectName, flavorName, logger); runListener.setReportDir(resultsDir); ((ShardedTestListener) runListener).setProgressListener(progressListener); runner.run(runListener);
private void addCodeCoverageInstrumentationArgs(RemoteAndroidTestRunner runner, IDevice device) throws Exception { String coveragePath = getExternalStoragePath(device, COVERAGE_FILE); runner.addInstrumentationArg("coverage", "true"); runner.addInstrumentationArg("coverageFile", coveragePath); }
/** * {@inheritDoc} */ public void run(ITestRunListener... listeners) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { run(Arrays.asList(listeners)); }
/** * {@inheritDoc} */ public void setLogOnly(boolean logOnly) { addBooleanArg(LOG_ARG_NAME, logOnly); }
@Override public void setMethodName(String className, String testName) { setClassName(className + METHOD_SEPARATOR + testName); }
RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner( testData.getApplicationId(), testData.getInstrumentationRunner(), runner.addInstrumentationArg(argument.getKey(), argument.getValue()); runner.addInstrumentationArg("coverage", "true"); runner.addInstrumentationArg("coverageFile", coverageFile); runner.setRunOptions("--no_window_animation"); runner.setRunName(deviceName); runner.setMaxtimeToOutputResponse(timeoutInMs); runner.run(runListener);
instrumentationInfo.getApplicationPackage(), testPackage, testRunner, device, clearAppDataBeforeEachTest, debug); runner.setMaxTimeToOutputResponse(adbTimeout.toMillis(), TimeUnit.MILLISECONDS); continue; runner.addInstrumentationArg(entry.getKey(), entry.getValue()); runner.setClassName(className); } else { runner.setMethodName(className, methodName); runner.setTestSize(testSize);