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); |
+ } |
+} |