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

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

Issue 942083003: Add a custom Robolectric testrunner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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: testing/android/junit/java/src/org/chromium/testing/local/ChromeRobolectricTestRunner.java
diff --git a/testing/android/junit/java/src/org/chromium/testing/local/ChromeRobolectricTestRunner.java b/testing/android/junit/java/src/org/chromium/testing/local/ChromeRobolectricTestRunner.java
new file mode 100644
index 0000000000000000000000000000000000000000..a3ba37dd4a7ffedfb77fdc9a45fa75e0ad638eb1
--- /dev/null
+++ b/testing/android/junit/java/src/org/chromium/testing/local/ChromeRobolectricTestRunner.java
@@ -0,0 +1,54 @@
+// 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 Robolectric Junit4 Test Runner customized to load the "real" android jars
jbudorick 2015/02/27 15:12:48 nit: Shorten the first sentence & go into a bit mo
mikecase (-- gone --) 2015/03/02 19:08:38 Done.
+ * from Chromium directory rather than use Maven to fetch them from the
+ * Maven Central repository.
+ */
+public class ChromeRobolectricTestRunner extends RobolectricTestRunner {
+
+ public ChromeRobolectricTestRunner(Class<?> testClass) throws InitializationError {
+ super(testClass);
+ }
+
+ @Override
+ protected final DependencyResolver getJarResolver() {
+ File dependencyDir;
+ if (System.getProperty("robolectric.dependency.dir") == 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.");
+ } else {
+ dependencyDir = new File(System.getProperty("robolectric.dependency.dir"));
+ }
+ return new LocalDependencyResolver(dependencyDir);
+ }
+
+ @Override
+ protected SdkConfig pickSdkVersion(AndroidManifest appManifest, Config config) {
+ // Pulling from the manifest is dangerous as Chrome 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(18) : super.pickSdkVersion(null, config);
jbudorick 2015/02/27 15:12:48 Robolectric has the android 5.0 jar up in Maven: h
mikecase (-- gone --) 2015/03/02 19:08:38 The robolectric prebuilt doesn't exist yet that su
+ }
+
+ @Override
+ protected int pickReportedSdkVersion(Config config, AndroidManifest appManifest) {
+ return config.reportSdk() < 0 ? 18 : super.pickReportedSdkVersion(config, appManifest);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698