Search in sources :

Example 1 with ITestRunListener

use of com.android.ddmlib.testrunner.ITestRunListener 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)

Aggregations

IDevice (com.android.ddmlib.IDevice)1 ITestRunListener (com.android.ddmlib.testrunner.ITestRunListener)1 RemoteAndroidTestRunner (com.android.ddmlib.testrunner.RemoteAndroidTestRunner)1 TestIdentifier (com.android.ddmlib.testrunner.TestIdentifier)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1