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

Unified Diff: testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java

Issue 942083003: Add a custom Robolectric testrunner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « testing/android/junit/BUILD.gn ('k') | testing/android/junit/junit_test.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java
diff --git a/testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java b/testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java
new file mode 100644
index 0000000000000000000000000000000000000000..293525ee7170cfedf8ff9e72202a542e01c7a6d4
--- /dev/null
+++ b/testing/android/junit/java/src/org/chromium/testing/local/LocalRobolectricTestRunner.java
@@ -0,0 +1,58 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.testing.local;
+
+import org.junit.runners.model.InitializationError;
+
+import org.robolectric.AndroidManifest;
+import org.robolectric.DependencyResolver;
+import org.robolectric.LocalDependencyResolver;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.SdkConfig;
+import org.robolectric.annotation.Config;
+
+import java.io.File;
+
+/**
+ * A custom Robolectric Junit4 Test Runner. This test runner will load the
+ * "real" android jars from a local directory rather than use Maven to fetch
+ * them from the Maven Central repository. Additionally, it will ignore the
+ * API level written in the AndroidManifest as that can cause issues if
+ * robolectric does not support that API level.
+ */
+public class LocalRobolectricTestRunner extends RobolectricTestRunner {
+
+ private static final int ANDROID_API_LEVEL = 18;
+
+ public LocalRobolectricTestRunner(Class<?> testClass) throws InitializationError {
+ super(testClass);
+ }
+
+ @Override
+ protected final DependencyResolver getJarResolver() {
kzaikin 2015/03/23 13:18:03 You don't really have to override this method If
+ String dependencyDir = System.getProperty("robolectric.dependency.dir");
+ if (dependencyDir == null) {
+ throw new IllegalStateException("robolectric.dependency.dir not specified. Make sure"
+ + " you are setting the robolectric.dependency.dir system property to the"
+ + " directory containing Robolectric's runtime dependency jars.");
+ }
+ return new LocalDependencyResolver(new File(dependencyDir));
+ }
+
+ @Override
+ protected SdkConfig pickSdkVersion(AndroidManifest appManifest, Config config) {
+ // Pulling from the manifest is dangerous as the apk might target a version of
+ // android that robolectric does not yet support. We still allow the API level to
+ // be overridden with the Config annotation.
+ return config.emulateSdk() < 0
+ ? new SdkConfig(ANDROID_API_LEVEL) : super.pickSdkVersion(null, config);
+ }
+
+ @Override
+ protected int pickReportedSdkVersion(Config config, AndroidManifest appManifest) {
+ return config.reportSdk() < 0
+ ? ANDROID_API_LEVEL : super.pickReportedSdkVersion(config, appManifest);
+ }
+}
« no previous file with comments | « testing/android/junit/BUILD.gn ('k') | testing/android/junit/junit_test.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698