Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2396)

Unified Diff: base/test/android/javatests/src/org/chromium/base/test/BaseChromiumAndroidJUnitRunner.java

Issue 2935503002: List Java Instru Test Information From JUnit Runner (Closed)
Patch Set: remove system println Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/test/android/javatests/src/org/chromium/base/test/BaseChromiumAndroidJUnitRunner.java
diff --git a/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumAndroidJUnitRunner.java b/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumAndroidJUnitRunner.java
index a48c4ab71301190bef89adf33a2a056832068600..9ff1c3db4aad013c93e384c8cb0125d22b106894 100644
--- a/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumAndroidJUnitRunner.java
+++ b/base/test/android/javatests/src/org/chromium/base/test/BaseChromiumAndroidJUnitRunner.java
@@ -4,20 +4,33 @@
package org.chromium.base.test;
+import android.app.Activity;
import android.app.Application;
+import android.app.Instrumentation;
import android.content.Context;
+import android.os.Bundle;
+import android.support.test.internal.runner.RunnerArgs;
+import android.support.test.internal.runner.TestExecutor;
+import android.support.test.internal.runner.TestRequest;
+import android.support.test.internal.runner.TestRequestBuilder;
import android.support.test.runner.AndroidJUnitRunner;
+import org.chromium.base.Log;
import org.chromium.base.multidex.ChromiumMultiDexInstaller;
/**
- * A custom AndroidJUnitRunner that supports multidex installer.
+ * A custom AndroidJUnitRunner that supports multidex installer and list out test information.
*
* This class is the equivalent of BaseChromiumInstrumentationTestRunner in JUnit3. Please
* beware that is this not a class runner. It is declared in test apk AndroidManifest.xml
* <instrumentation>
*/
public class BaseChromiumAndroidJUnitRunner extends AndroidJUnitRunner {
+ private Bundle mArguments;
+ private static final String LIST_ALL_TESTS_FLAG =
+ "org.chromium.base.test.BaseChromiumAndroidJUnitRunner.TestList";
+ private static final String TAG = "BaseJUnitRunner";
+
@Override
public Application newApplication(ClassLoader cl, String className, Context context)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
@@ -26,4 +39,53 @@ public class BaseChromiumAndroidJUnitRunner extends AndroidJUnitRunner {
BaseChromiumRunnerCommon.reorderDexPathElements(cl, getContext(), getTargetContext());
return super.newApplication(cl, className, context);
}
+
+ @Override
+ public void onCreate(Bundle arguments) {
+ super.onCreate(arguments);
+ mArguments = arguments;
+ }
+
+ /**
+ * Add TestListInstrumentationRunListener when argument ask the runner to list tests info.
+ *
+ * The running mechanism when argument has "listAllTests" is equivalent to that of
+ * {@link android.support.test.runner.AndroidJUnitRunner#onStart()} except it adds
+ * only TestListInstrumentationRunListener to monitor the tests.
+ */
+ @Override
+ public void onStart() {
+ if (mArguments.getString(LIST_ALL_TESTS_FLAG) != null) {
+ listTests();
+ } else {
+ super.onStart();
+ }
+ }
+
+ private void listTests() {
+ Bundle results = new Bundle();
+ try {
+ TestExecutor.Builder executorBuilder = new TestExecutor.Builder(this);
+ executorBuilder.addRunListener(new TestListInstrumentationRunListener(
+ mArguments.getString(LIST_ALL_TESTS_FLAG)));
+ TestRequest listTestRequest = createListTestRequest(mArguments);
+ results = executorBuilder.build().execute(listTestRequest);
+ } catch (RuntimeException e) {
+ final String msg = "Fatal exception when running tests";
+ Log.e(TAG, msg, e);
+ // report the exception to instrumentation out
+ results.putString(Instrumentation.REPORT_KEY_STREAMRESULT,
+ msg + "\n" + Log.getStackTraceString(e));
+ }
+ finish(Activity.RESULT_OK, results);
+ }
+
+ private TestRequest createListTestRequest(Bundle arguments) {
+ RunnerArgs runnerArgs =
+ new RunnerArgs.Builder().fromManifest(this).fromBundle(arguments).build();
+ TestRequestBuilder builder = new TestRequestBuilder(this, arguments);
+ builder.addApkToScan(getContext().getPackageCodePath());
+ builder.addFromRunnerArgs(runnerArgs);
+ return builder.build();
+ }
}

Powered by Google App Engine
This is Rietveld 408576698