Search in sources :

Example 1 with RemoteAndroidTestRunner

use of com.android.ddmlib.testrunner.RemoteAndroidTestRunner in project buck by facebook.

the class InstrumentationTestRunner method run.

public void run() throws Throwable {
    IDevice device = getDevice(this.deviceSerial);
    if (device == null) {
        System.err.printf("Unable to get device/emulator with serial %s", this.deviceSerial);
        System.exit(1);
    }
    if (this.instrumentationApkPath != null) {
        DdmPreferences.setTimeOut(60000);
        device.installPackage(this.instrumentationApkPath, true);
        if (this.apkUnderTestPath != null) {
            device.installPackage(this.apkUnderTestPath, true);
        }
    }
    try {
        final RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner(this.packageName, this.testRunner, getDevice(deviceSerial));
        for (Map.Entry<String, String> entry : this.extraInstrumentationArguments.entrySet()) {
            runner.addInstrumentationArg(entry.getKey(), entry.getValue());
        }
        BuckXmlTestRunListener listener = new BuckXmlTestRunListener();
        ITestRunListener trimLineListener = new ITestRunListener() {

            /**
           * Before the actual run starts (and after the
           * InstrumentationResultsParser is created), we need to do
           * some reflection magic to make RemoteAndroidTestRunner not
           * trim indentation from lines.
           */
            @Override
            public void testRunStarted(String runName, int testCount) {
                setTrimLine(runner, false);
            }

            @Override
            public void testRunEnded(long elapsedTime, Map<String, String> runMetrics) {
            }

            @Override
            public void testRunFailed(String errorMessage) {
            }

            @Override
            public void testStarted(TestIdentifier test) {
            }

            @Override
            public void testFailed(TestIdentifier test, String trace) {
            }

            @Override
            public void testAssumptionFailure(TestIdentifier test, String trace) {
            }

            @Override
            public void testIgnored(TestIdentifier test) {
            }

            @Override
            public void testEnded(TestIdentifier test, Map<String, String> testMetrics) {
            }

            @Override
            public void testRunStopped(long elapsedTime) {
            }
        };
        listener.setReportDir(this.outputDirectory);
        runner.run(trimLineListener, listener);
    } finally {
        if (this.attemptUninstall) {
            // Best effort uninstall from the emulator/device.
            device.uninstallPackage(this.packageName);
        }
    }
}
Also used : ITestRunListener(com.android.ddmlib.testrunner.ITestRunListener) RemoteAndroidTestRunner(com.android.ddmlib.testrunner.RemoteAndroidTestRunner) IDevice(com.android.ddmlib.IDevice) TestIdentifier(com.android.ddmlib.testrunner.TestIdentifier) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with RemoteAndroidTestRunner

use of com.android.ddmlib.testrunner.RemoteAndroidTestRunner in project intellij by bazelbuild.

the class StockAndroidTestLaunchTask method perform.

@Override
@SuppressWarnings("FutureReturnValueIgnored")
public boolean perform(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 false;
    }
    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(launchStatus, printer));
        } catch (Exception e) {
            LOG.info(e);
            printer.stderr("Error: Unexpected exception while running tests: " + e);
        }
    });
    return true;
}
Also used : AndroidTestListener(com.android.tools.idea.testartifacts.instrumented.AndroidTestListener) RemoteAndroidTestRunner(com.android.ddmlib.testrunner.RemoteAndroidTestRunner) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException)

Example 3 with RemoteAndroidTestRunner

use of com.android.ddmlib.testrunner.RemoteAndroidTestRunner in project buck by facebook.

the class InstrumentationTestRunnerTest method testSetTrimLinesHappyPath.

/**
   * Just verifies the reflection is legit
   */
@Test
public void testSetTrimLinesHappyPath() throws Throwable {
    IShellEnabledDevice shellEnabledDevice = EasyMock.createMock(IShellEnabledDevice.class);
    EasyMock.replay(shellEnabledDevice);
    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);
}
Also used : Field(java.lang.reflect.Field) IShellEnabledDevice(com.android.ddmlib.IShellEnabledDevice) InstrumentationResultParser(com.android.ddmlib.testrunner.InstrumentationResultParser) RemoteAndroidTestRunner(com.android.ddmlib.testrunner.RemoteAndroidTestRunner) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with RemoteAndroidTestRunner

use of com.android.ddmlib.testrunner.RemoteAndroidTestRunner in project android-instrumental-test-runner by Grigory-Rylov.

the class TestRunnerBuilderTest method getTestRunner.

@Test
public void getTestRunner() throws Exception {
    RemoteAndroidTestRunner testRunner = builder.getTestRunner();
    Assert.assertNotNull(testRunner);
    Assert.assertEquals(TEST_PACKAGE, testRunner.getPackageName());
    Assert.assertEquals(RUNNER_NAME, testRunner.getRunnerName());
    testRunner.getAmInstrumentCommand();
    Assert.assertEquals("/data/data/com.test.packageId/coverage.ec", builder.getCoverageFile());
}
Also used : RemoteAndroidTestRunner(com.android.ddmlib.testrunner.RemoteAndroidTestRunner) Test(org.junit.Test)

Aggregations

RemoteAndroidTestRunner (com.android.ddmlib.testrunner.RemoteAndroidTestRunner)4 Test (org.junit.Test)2 IDevice (com.android.ddmlib.IDevice)1 IShellEnabledDevice (com.android.ddmlib.IShellEnabledDevice)1 ITestRunListener (com.android.ddmlib.testrunner.ITestRunListener)1 InstrumentationResultParser (com.android.ddmlib.testrunner.InstrumentationResultParser)1 TestIdentifier (com.android.ddmlib.testrunner.TestIdentifier)1 ApkProvisionException (com.android.tools.idea.run.ApkProvisionException)1 AndroidTestListener (com.android.tools.idea.testartifacts.instrumented.AndroidTestListener)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1