From a992fc4405d63491c909d387291f0f0512bd8324 Mon Sep 17 00:00:00 2001 From: Said Tahsin Dane Date: Sun, 25 Dec 2016 17:10:48 +0100 Subject: [PATCH 1/6] Modify gradle options --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 68a890de0..cffd9b969 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ jdk: env: global: - secure: "OVfIL3ggaGcDgJJhdWxYTCo3u38SNPNUNPsv6adHp5wW0Y2n1CF1zcAnZXhTkGEjoGvi0RuV8ZLG9jbmQdqxd17qBeBf2XPWKxyG1SUfegDVSy9OPF8BY11Fsp9I5RP1W3T/c32KTc7zvhtAivq9mbcrBYJZhDCKpZkdTNliFQ0=" - - GRADLE_OPTS="-Xms40m -Xmx3g -XX:MaxPermSize=3g" android: components: @@ -25,7 +24,8 @@ before_install: after_success: - if [ -n "$GITHUB_API_KEY" ]; then .buildscript/deploy_alpha.sh; fi -script: "./gradlew check" +script: + - ./gradlew check -Dorg.gradle.jvmargs="-Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError" -Dorg.gradle.daemon=false branches: except: From 7b151d109a9b7201c4f627d2cf4eaf4416f4f4ba Mon Sep 17 00:00:00 2001 From: Said Tahsin Dane Date: Sun, 25 Dec 2016 18:10:31 +0100 Subject: [PATCH 2/6] Add gcloud and firebase test lab support --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cffd9b969..6ad62068c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,12 @@ after_success: - if [ -n "$GITHUB_API_KEY" ]; then .buildscript/deploy_alpha.sh; fi script: - - ./gradlew check -Dorg.gradle.jvmargs="-Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError" -Dorg.gradle.daemon=false + - ./gradlew check assembleDebug assembleDebugAndroidTest -Dorg.gradle.jvmargs="-Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError" -Dorg.gradle.daemon=false + - wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-138.0.0-linux-x86_64.tar.gz + - tar xf google-cloud-sdk-138.0.0-linux-x86_64.tar.gz + - echo "y" | ./google-cloud-sdk/bin/gcloud components update beta + - ./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file settings/firebase-test-lab.json + - ./google-cloud-sdk/bin/gcloud beta test android run --async --type instrumentation --app ./app/build/output/apk/app-debug.apk --test ./app/build/output/apk/app-debug-androidTest.apk --device-ids Nexus5 --os-version-ids 22 --locales en --orientations portrait --project api-project-429371117063 branches: except: From 13f8d90e80cf65a812e3b05162cc3e8495b59183 Mon Sep 17 00:00:00 2001 From: Said Tahsin Dane Date: Sun, 25 Dec 2016 18:21:22 +0100 Subject: [PATCH 3/6] Do not output account activation --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6ad62068c..ef45fdf39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ script: - wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-138.0.0-linux-x86_64.tar.gz - tar xf google-cloud-sdk-138.0.0-linux-x86_64.tar.gz - echo "y" | ./google-cloud-sdk/bin/gcloud components update beta - - ./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file settings/firebase-test-lab.json + - ./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file settings/firebase-test-lab.json >/dev/null - ./google-cloud-sdk/bin/gcloud beta test android run --async --type instrumentation --app ./app/build/output/apk/app-debug.apk --test ./app/build/output/apk/app-debug-androidTest.apk --device-ids Nexus5 --os-version-ids 22 --locales en --orientations portrait --project api-project-429371117063 branches: From de748b7b260ed6c60f9df8d30f239ab8be20b05c Mon Sep 17 00:00:00 2001 From: Said Tahsin Dane Date: Sun, 25 Dec 2016 18:30:00 +0100 Subject: [PATCH 4/6] Fix typo on folder name --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ef45fdf39..38a5c07b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ script: - tar xf google-cloud-sdk-138.0.0-linux-x86_64.tar.gz - echo "y" | ./google-cloud-sdk/bin/gcloud components update beta - ./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file settings/firebase-test-lab.json >/dev/null - - ./google-cloud-sdk/bin/gcloud beta test android run --async --type instrumentation --app ./app/build/output/apk/app-debug.apk --test ./app/build/output/apk/app-debug-androidTest.apk --device-ids Nexus5 --os-version-ids 22 --locales en --orientations portrait --project api-project-429371117063 + - ./google-cloud-sdk/bin/gcloud beta test android run --async --type instrumentation --app ./app/build/outputs/apk/app-debug.apk --test ./app/build/outputs/apk/app-debug-androidTest.apk --device-ids Nexus5 --os-version-ids 22 --locales en --orientations portrait --project api-project-429371117063 branches: except: From b045ad8c64a9f94dc5502e6cf3f29e8122b43836 Mon Sep 17 00:00:00 2001 From: Said Tahsin Dane Date: Sat, 24 Dec 2016 19:39:38 +0100 Subject: [PATCH 5/6] Have special test runner and app to have initial settings for tests Disable Season Greetings on tests. Tests should not fail on christmas :) --- app/build.gradle | 2 +- .../frisbee/android/FrisbeeTestRunner.java | 16 ++++++++++++++++ .../activity/MainActivityDeepLinkTest.java | 9 +-------- .../android/activity/MainActivityTest.java | 1 - .../org/gdg/frisbee/android/app/TestApp.java | 15 +++++++++++++++ .../gdg/frisbee/android/utils/PrefUtils.java | 19 ++++++++++++++++--- 6 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 app/src/androidTest/java/org/gdg/frisbee/android/FrisbeeTestRunner.java create mode 100644 app/src/androidTest/java/org/gdg/frisbee/android/app/TestApp.java diff --git a/app/build.gradle b/app/build.gradle index 803f4139e..e43ba9469 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,7 +37,7 @@ android { resConfigs "en", "ar", "cs", "de", "es", "fr", "hi", "hu", "hy-rAM", "it", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "sr", "sk", "th", "tr", "uk", "zh-rCN", "zh-rHK", "zh-rTW" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "org.gdg.frisbee.android.FrisbeeTestRunner" //KEYS buildConfigField "long", "DOORBELL_ID", local_properties.doorbell_id ?: "0" diff --git a/app/src/androidTest/java/org/gdg/frisbee/android/FrisbeeTestRunner.java b/app/src/androidTest/java/org/gdg/frisbee/android/FrisbeeTestRunner.java new file mode 100644 index 000000000..dc297871f --- /dev/null +++ b/app/src/androidTest/java/org/gdg/frisbee/android/FrisbeeTestRunner.java @@ -0,0 +1,16 @@ +package org.gdg.frisbee.android; + +import android.app.Application; +import android.content.Context; +import android.support.test.runner.AndroidJUnitRunner; + +import org.gdg.frisbee.android.app.TestApp; + +public class FrisbeeTestRunner extends AndroidJUnitRunner { + + @Override + public Application newApplication(ClassLoader cl, String className, Context context) + throws InstantiationException, IllegalAccessException, ClassNotFoundException { + return super.newApplication(cl, TestApp.class.getName(), context); + } +} diff --git a/app/src/androidTest/java/org/gdg/frisbee/android/activity/MainActivityDeepLinkTest.java b/app/src/androidTest/java/org/gdg/frisbee/android/activity/MainActivityDeepLinkTest.java index 9e28e4255..707e039c8 100644 --- a/app/src/androidTest/java/org/gdg/frisbee/android/activity/MainActivityDeepLinkTest.java +++ b/app/src/androidTest/java/org/gdg/frisbee/android/activity/MainActivityDeepLinkTest.java @@ -2,14 +2,12 @@ import android.content.Intent; import android.net.Uri; -import android.support.test.InstrumentationRegistry; import android.support.test.espresso.ViewInteraction; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.support.v7.widget.Toolbar; import org.gdg.frisbee.android.chapter.MainActivity; -import org.gdg.frisbee.android.utils.PrefUtils; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,12 +27,7 @@ public class MainActivityDeepLinkTest { private static final Uri URI_GDG_BRUSSELS = Uri.parse("https://developers.google.com/groups/chapter/105068877693379070381/"); @Rule - public ActivityTestRule activityRule = new ActivityTestRule(MainActivity.class, true, false) { - @Override - protected void beforeActivityLaunched() { - PrefUtils.setInitialSettings(InstrumentationRegistry.getTargetContext(), false); - } - }; + public ActivityTestRule activityRule = new ActivityTestRule<>(MainActivity.class, true, false); @Test public void canHandleDevelopersGoogleChapterUri() { diff --git a/app/src/androidTest/java/org/gdg/frisbee/android/activity/MainActivityTest.java b/app/src/androidTest/java/org/gdg/frisbee/android/activity/MainActivityTest.java index 3ad696055..26d6b90f2 100644 --- a/app/src/androidTest/java/org/gdg/frisbee/android/activity/MainActivityTest.java +++ b/app/src/androidTest/java/org/gdg/frisbee/android/activity/MainActivityTest.java @@ -41,7 +41,6 @@ public class MainActivityTest { public ActivityTestRule activityRule = new ActivityTestRule(MainActivity.class) { @Override protected void beforeActivityLaunched() { - PrefUtils.setInitialSettings(InstrumentationRegistry.getTargetContext(), false); PrefUtils.setHomeChapter(InstrumentationRegistry.getTargetContext(), CHAPTER_BRUSSELS); } }; diff --git a/app/src/androidTest/java/org/gdg/frisbee/android/app/TestApp.java b/app/src/androidTest/java/org/gdg/frisbee/android/app/TestApp.java new file mode 100644 index 000000000..57df04b05 --- /dev/null +++ b/app/src/androidTest/java/org/gdg/frisbee/android/app/TestApp.java @@ -0,0 +1,15 @@ +package org.gdg.frisbee.android.app; + + +import org.gdg.frisbee.android.utils.PrefUtils; + +public class TestApp extends App { + + @Override + public void onCreate() { + super.onCreate(); + + PrefUtils.setInitialSettings(this, false); + PrefUtils.skipSeasonsGreetings(this); + } +} diff --git a/app/src/main/java/org/gdg/frisbee/android/utils/PrefUtils.java b/app/src/main/java/org/gdg/frisbee/android/utils/PrefUtils.java index 1b2d512ea..00dcf9bfa 100644 --- a/app/src/main/java/org/gdg/frisbee/android/utils/PrefUtils.java +++ b/app/src/main/java/org/gdg/frisbee/android/utils/PrefUtils.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.support.annotation.Nullable; +import android.support.annotation.RestrictTo; import com.crashlytics.android.Crashlytics; @@ -113,7 +114,7 @@ public static int getAppStarts(final Context context) { return prefs(context).getInt(PREFS_APP_STARTS, 0); } - public static boolean shouldShowSeasonsGreetings(final Context context) { + public static boolean shouldShowSeasonsGreetings(Context context) { DateTime now = DateTime.now(); if (prefs(context).getInt(PREFS_SEASONS_GREETINGS, now.getYear() - 1) < now.getYear() && (now.getDayOfYear() >= 354 && now.getDayOfYear() <= 366)) { @@ -123,11 +124,23 @@ public static boolean shouldShowSeasonsGreetings(final Context context) { return false; } - public static void setVersionCode(final Context context, final int newVersion) { + @RestrictTo(RestrictTo.Scope.TESTS) + public static void skipSeasonsGreetings(Context context) { + prefs(context) + .edit() + .putInt(PREFS_SEASONS_GREETINGS, DateTime.now().getYear()) + .apply(); + } + + public static void setVersionCode(Context context, int newVersion) { prefs(context).edit().putInt(PREFS_VERSION_CODE, newVersion).apply(); } - public static void resetInitialSettings(final Context context) { + /** + * Used in alpha source set + */ + @SuppressWarnings("unused") + public static void resetInitialSettings(Context context) { prefs(context).edit() .clear() .apply(); From de422bdd27b9c5b858efebd78d7d02b0e9b99259 Mon Sep 17 00:00:00 2001 From: Said Tahsin Dane Date: Sun, 25 Dec 2016 21:06:41 +0100 Subject: [PATCH 6/6] Move firebase test lab test initialization into its own script --- .buildscript/firebase_tests.sh | 23 +++++++++++++++++++++++ .travis.yml | 6 +----- 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100755 .buildscript/firebase_tests.sh diff --git a/.buildscript/firebase_tests.sh b/.buildscript/firebase_tests.sh new file mode 100755 index 000000000..97bf9def4 --- /dev/null +++ b/.buildscript/firebase_tests.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Use gcloud from Google to run Espresso tests on Firebase Test Lab + +SLUG="gdg-x/frisbee" +BRANCH='develop'; + +if [ "$TRAVIS_REPO_SLUG" != "$SLUG" ]; then + echo "Skipping tests on Firebase: wrong repository. Expected '$SLUG' but was '$TRAVIS_REPO_SLUG'." +elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then + echo "Skipping tests on Firebase: was pull request." +elif [ "$TRAVIS_BRANCH" != "$BRANCH" ]; then + echo "Skipping tests on Firebase: wrong branch. Expected '$BRANCH' but was '$TRAVIS_BRANCH'." +else + echo "Starting tests on Firebase" + + wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-138.0.0-linux-x86_64.tar.gz + tar xf google-cloud-sdk-138.0.0-linux-x86_64.tar.gz + echo "y" | ./google-cloud-sdk/bin/gcloud components update beta + ./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file settings/firebase-test-lab.json >/dev/null + ./google-cloud-sdk/bin/gcloud beta test android run --async --type instrumentation --app ./app/build/outputs/apk/app-debug.apk --test ./app/build/outputs/apk/app-debug-androidTest.apk --device-ids Nexus5 --os-version-ids 22 --project api-project-429371117063 + + echo "Test APK upload to Firebase complete" +fi diff --git a/.travis.yml b/.travis.yml index 38a5c07b0..14b17d939 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,11 +26,7 @@ after_success: script: - ./gradlew check assembleDebug assembleDebugAndroidTest -Dorg.gradle.jvmargs="-Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError" -Dorg.gradle.daemon=false - - wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-138.0.0-linux-x86_64.tar.gz - - tar xf google-cloud-sdk-138.0.0-linux-x86_64.tar.gz - - echo "y" | ./google-cloud-sdk/bin/gcloud components update beta - - ./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file settings/firebase-test-lab.json >/dev/null - - ./google-cloud-sdk/bin/gcloud beta test android run --async --type instrumentation --app ./app/build/outputs/apk/app-debug.apk --test ./app/build/outputs/apk/app-debug-androidTest.apk --device-ids Nexus5 --os-version-ids 22 --locales en --orientations portrait --project api-project-429371117063 + - .buildscript/firebase_tests.sh branches: except: