work around to use AndroidJUnit Test Runner.. \n use ./gradlew app:connectedLocalPhotonDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.annotation=org.mozilla.gecko.TestEnvOnly draft
authorNevin Chen <cnevinchen@gmail.com>
Thu, 23 Nov 2017 18:36:43 +0800
changeset 708916 38d52cf57a10381fd81ab482cd9c2d8be141d924
parent 708915 654a99911dbfee9d3030587d54ba0e0f4c569eab
child 708917 4594af36865115ecbfd438530e0434907178a11f
push id92480
push userbmo:cnevinchen@gmail.com
push dateThu, 07 Dec 2017 09:53:01 +0000
milestone59.0a1
work around to use AndroidJUnit Test Runner.. \n use ./gradlew app:connectedLocalPhotonDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.annotation=org.mozilla.gecko.TestEnvOnly to run this special anotated espresso test. TODO: specify the test runner in command line.. or even better to make it a gradle task espressoTest Task.. for example MozReview-Commit-ID: CU3pyDCVPwa
mobile/android/app/build.gradle
mobile/android/app/src/androidTest/java/org/mozilla/gecko/EspressoBrowserAppTest.java
mobile/android/app/src/androidTest/java/org/mozilla/gecko/TestEnvOnly.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/HelloWorldEspressoTest.java
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -20,18 +20,17 @@ android {
 
         applicationId mozconfig.substs.ANDROID_PACKAGE_NAME
         testApplicationId 'org.mozilla.roboexample.test'
         testInstrumentationRunner 'org.mozilla.gecko.FennecInstrumentationTestRunner'
         // Used by Robolectric based tests; see TestRunner.
         buildConfigField 'String', 'BUILD_DIR', "\"${project.buildDir}\""
 
         vectorDrawables.useSupportLibrary = true
-        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
-
+        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
     }
 
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_7
         targetCompatibility JavaVersion.VERSION_1_7
     }
 
     dexOptions {
@@ -109,16 +108,17 @@ android {
              dimension "audience"
         }
 
         // Since Firefox 57, the mobile user interface has followed the Photon design.
         // Before Firefox 57, the user interface followed the Australis design.
         photon {
             dimension "skin"
         }
+
     }
 
     sourceSets {
         main {
             aidl {
                 srcDir "${topsrcdir}/mobile/android/base/aidl"
             }
 
@@ -207,16 +207,18 @@ android {
         }
 
         androidTest {
             java {
                 srcDir "${topsrcdir}/mobile/android/tests/browser/robocop/src"
                 // Bug 1229149 tracks pushing this into a :services Gradle project.
                 srcDir "${topsrcdir}/mobile/android/services/src/androidTest/java"
                 srcDir "${topsrcdir}/mobile/android/tests/browser/junit3/src"
+                srcDir "${topsrcdir}/mobile/android/app/src/androidTest/java"
+
             }
             res {
                 srcDir "${topsrcdir}/mobile/android/tests/browser/robocop/res"
             }
             assets {
                 srcDir "${topsrcdir}/mobile/android/tests/browser/robocop/assets"
             }
         }
new file mode 100644
--- /dev/null
+++ b/mobile/android/app/src/androidTest/java/org/mozilla/gecko/EspressoBrowserAppTest.java
@@ -0,0 +1,22 @@
+package org.mozilla.gecko;
+
+import android.support.test.rule.ActivityTestRule;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@TestEnvOnly
+@RunWith(AndroidJUnit4.class)
+public class EspressoBrowserAppTest {
+
+    @Rule
+    public ActivityTestRule<BrowserApp> mActivityRule =
+            new ActivityTestRule(BrowserApp.class);
+
+    @Test
+    public void listGoesOverTheFold() {
+
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/app/src/androidTest/java/org/mozilla/gecko/TestEnvOnly.java
@@ -0,0 +1,14 @@
+package org.mozilla.gecko;
+
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+// https://medium.com/@satyajit/running-subset-of-espresso-tests-locally-and-gcloud-4713931da56
+//Needed to have annotations at a test level
+@Target({ ElementType.METHOD, ElementType.TYPE })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TestEnvOnly {
+}
\ No newline at end of file
deleted file mode 100644
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/HelloWorldEspressoTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.mozilla.gecko;
-
-import android.support.test.filters.LargeTest;
-import android.support.test.rule.ActivityTestRule;
-import android.support.test.runner.AndroidJUnit4;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static android.support.test.espresso.Espresso.onView;
-import static android.support.test.espresso.assertion.ViewAssertions.matches;
-import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static android.support.test.espresso.matcher.ViewMatchers.withId;
-import static android.support.test.espresso.matcher.ViewMatchers.withText;
-
-@RunWith(AndroidJUnit4.class)
-@LargeTest
-public class HelloWorldEspressoTest {
-
-    @Rule
-    public ActivityTestRule<BrowserApp> mActivityRule =
-            new ActivityTestRule(BrowserApp.class);
-
-    @Test
-    public void listGoesOverTheFold() {
-
-    }
-}