com.android.ddmlib.testrunner.RemoteAndroidTestRunner Java Examples

The following examples show how to use com.android.ddmlib.testrunner.RemoteAndroidTestRunner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestLaunchAction.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
    public boolean doLaunch(LaunchInfo launchInfo, final IDevice device, final Project project, MainActivityConfiguration mainActivityConfiguration) {
        Preconditions.checkNotNull(project);
        String runnerClass = launchInfo.launchConfig.getInstrumentationRunner();
        final RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner(
                launchInfo.manifestData.getPackage(),
                runnerClass != null ? runnerClass : AndroidProjectProperties.INSTR_RUNNER_DEFAULT,
                device);

        if (!Strings.isNullOrEmpty(launchInfo.testClass)) {
//        if (mLaunchInfo.getTestMethod() != null) {
//            runner.setMethodName(mLaunchInfo.getTestClass(), mLaunchInfo.getTestMethod());
//        } else {
            runner.setClassName(launchInfo.testClass);
//        }
        }
//
//    if (mLaunchInfo.getTestPackage() != null) {
//        runner.setTestPackageName(mLaunchInfo.getTestPackage());
//    }
        runner.setDebug(launchInfo.debug);

        if (launchInfo.debug) {
            // TODO this is wrong
            // we need to start test runner asynchronously to be able to attach
            RequestProcessor.getDefault().post(new Runnable() {

                @Override
                public void run() {
                    callRunner(runner, device, project);
                }
            });
            return true;
        }
        return callRunner(runner, device, project);
    }
 
Example #2
Source File: InstrumentationTestRunner.java    From buck with Apache License 2.0 5 votes vote down vote up
static void setTrimLine(RemoteAndroidTestRunner runner, boolean value) {
  try {
    Field mParserField = RemoteAndroidTestRunner.class.getDeclaredField("mParser");
    mParserField.setAccessible(true);
    MultiLineReceiver multiLineReceiver = (MultiLineReceiver) mParserField.get(runner);
    multiLineReceiver.setTrimLine(value);
  } catch (NoSuchFieldException | IllegalAccessException e) {
    throw new RuntimeException(e);
  }
}
 
Example #3
Source File: InstrumentationTestRunnerTest.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Just verifies the reflection is legit */
@Test
public void testSetTrimLinesHappyPath() throws Throwable {
  IShellEnabledDevice shellEnabledDevice = new TestDevice();
  RemoteAndroidTestRunner runner =
      new RemoteAndroidTestRunner("foobar", "blah", shellEnabledDevice);

  Field field = RemoteAndroidTestRunner.class.getDeclaredField("mParser");
  field.setAccessible(true);
  field.set(runner, new InstrumentationResultParser("fooBar", new ArrayList<ITestRunListener>()));

  InstrumentationTestRunner.setTrimLine(runner, true);
}
 
Example #4
Source File: StockAndroidTestLaunchTask.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("FutureReturnValueIgnored")
public LaunchResult run(
    Executor executor,
    IDevice device,
    final LaunchStatus launchStatus,
    final ConsolePrinter printer) {
  printer.stdout("Running tests\n");

  final RemoteAndroidTestRunner runner =
      new RemoteAndroidTestRunner(testApplicationId, instrumentationTestRunner, device);
  switch (configState.getTestingType()) {
    case BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_MODULE:
      break;
    case BlazeAndroidTestRunConfigurationState.TEST_ALL_IN_PACKAGE:
      runner.setTestPackageName(configState.getPackageName());
      break;
    case BlazeAndroidTestRunConfigurationState.TEST_CLASS:
      runner.setClassName(configState.getClassName());
      break;
    case BlazeAndroidTestRunConfigurationState.TEST_METHOD:
      runner.setMethodName(configState.getClassName(), configState.getMethodName());
      break;
    default:
      LOG.error(String.format("Unrecognized testing type: %d", configState.getTestingType()));
      return LaunchResult.error("", getDescription());
  }
  runner.setDebug(waitForDebugger);
  runner.setRunOptions(configState.getExtraOptions());

  printer.stdout("$ adb shell " + runner.getAmInstrumentCommand());

  // run in a separate thread as this will block until the tests complete
  ApplicationManager.getApplication()
      .executeOnPooledThread(
          () -> {
            try {
              runner.run(new AndroidTestListener(printer));
            } catch (Exception e) {
              LOG.info(e);
              printer.stderr("Error: Unexpected exception while running tests: " + e);
            }
          });

  return LaunchResult.success();
}