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);
}
}
}
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;
}
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);
}
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());
}
Aggregations