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

Side by Side 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: List tests from Android Instrumentation test runner 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.base.test; 5 package org.chromium.base.test;
6 6
7 import android.app.Activity;
7 import android.app.Application; 8 import android.app.Application;
9 import android.app.Instrumentation;
8 import android.content.Context; 10 import android.content.Context;
11 import android.os.Bundle;
12 import android.support.test.internal.runner.RunnerArgs;
13 import android.support.test.internal.runner.TestExecutor;
14 import android.support.test.internal.runner.TestRequest;
15 import android.support.test.internal.runner.TestRequestBuilder;
9 import android.support.test.runner.AndroidJUnitRunner; 16 import android.support.test.runner.AndroidJUnitRunner;
10 17
18 import org.chromium.base.Log;
11 import org.chromium.base.multidex.ChromiumMultiDexInstaller; 19 import org.chromium.base.multidex.ChromiumMultiDexInstaller;
12 20
13 /** 21 /**
14 * A custom AndroidJUnitRunner that supports multidex installer. 22 * A custom AndroidJUnitRunner that supports multidex installer.
15 * 23 *
16 * This class is the equivalent of BaseChromiumInstrumentationTestRunner in JUni t3. Please 24 * This class is the equivalent of BaseChromiumInstrumentationTestRunner in JUni t3. Please
17 * beware that is this not a class runner. It is declared in test apk AndroidMan ifest.xml 25 * beware that is this not a class runner. It is declared in test apk AndroidMan ifest.xml
18 * <instrumentation> 26 * <instrumentation>
19 */ 27 */
20 public class BaseChromiumAndroidJUnitRunner extends AndroidJUnitRunner { 28 public class BaseChromiumAndroidJUnitRunner extends AndroidJUnitRunner {
29 private Bundle mArguments;
30 private static final String LIST_ALL_TESTS_FLAG = "listAllTests";
31 private static final String TAG = "BaseJUnitRunner";
32
21 @Override 33 @Override
22 public Application newApplication(ClassLoader cl, String className, Context context) 34 public Application newApplication(ClassLoader cl, String className, Context context)
23 throws ClassNotFoundException, IllegalAccessException, Instantiation Exception { 35 throws ClassNotFoundException, IllegalAccessException, Instantiation Exception {
24 ChromiumMultiDexInstaller.install(new BaseChromiumRunnerCommon.MultiDexC ontextWrapper( 36 ChromiumMultiDexInstaller.install(new BaseChromiumRunnerCommon.MultiDexC ontextWrapper(
25 getContext(), getTargetContext())); 37 getContext(), getTargetContext()));
26 BaseChromiumRunnerCommon.reorderDexPathElements(cl, getContext(), getTar getContext()); 38 BaseChromiumRunnerCommon.reorderDexPathElements(cl, getContext(), getTar getContext());
27 return super.newApplication(cl, className, context); 39 return super.newApplication(cl, className, context);
28 } 40 }
41
42 @Override
43 public void onCreate(Bundle arguments) {
44 super.onCreate(arguments);
45 mArguments = arguments;
46 }
47
48 @Override
49 public void onStart() {
50 if (getListTestFlag(mArguments) != null) {
51 Bundle results = new Bundle();
52 try {
53 TestExecutor.Builder executorBuilder = new TestExecutor.Builder( this);
54 executorBuilder.addRunListener(new TestListInstrumentationRunLis tener(
55 getListTestFlag(mArguments).toString()));
56 TestRequest listTestRequest = createListTestRequest(mArguments);
57 results = executorBuilder.build().execute(listTestRequest);
mikecase (-- gone --) 2017/07/11 21:14:51 can you explain how this works? How did you make t
the real yoland 2017/07/14 03:15:46 I am using the AndroidJUnitRunner's provided featu
58 } catch (RuntimeException e) {
mikecase (-- gone --) 2017/07/11 21:14:51 Should we actually be catching this? Will the exce
the real yoland 2017/07/14 03:15:46 The failure stack trace will show up in the host s
59 final String msg = "Fatal exception when running tests";
60 Log.e(TAG, msg, e);
61 // report the exception to instrumentation out
62 results.putString(Instrumentation.REPORT_KEY_STREAMRESULT,
63 msg + "\n" + Log.getStackTraceString(e));
64 }
65 finish(Activity.RESULT_OK, results);
66 } else {
67 super.onStart();
68 }
69 }
70
71 private TestRequest createListTestRequest(Bundle arguments) {
72 RunnerArgs runnerArgs =
73 new RunnerArgs.Builder().fromManifest(this).fromBundle(arguments ).build();
74 TestRequestBuilder builder = new TestRequestBuilder(this, arguments);
75 builder.addApkToScan(getContext().getPackageCodePath());
76 builder.addFromRunnerArgs(runnerArgs);
77 return builder.build();
78 }
79
80 private static CharSequence getListTestFlag(Bundle arguments) {
81 return arguments != null ? arguments.getCharSequence(LIST_ALL_TESTS_FLAG ) : null;
82 }
29 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698