Skip to content

Commit

Permalink
Merge pull request #713 from gdg-x/experiment/firebase-test-lab
Browse files Browse the repository at this point in the history
Integrate firebase test lab
  • Loading branch information
tasomaniac authored Jan 2, 2017
2 parents cab4187 + de422bd commit 5a5959a
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 15 deletions.
23 changes: 23 additions & 0 deletions .buildscript/firebase_tests.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ jdk:
env:
global:
- secure: "OVfIL3ggaGcDgJJhdWxYTCo3u38SNPNUNPsv6adHp5wW0Y2n1CF1zcAnZXhTkGEjoGvi0RuV8ZLG9jbmQdqxd17qBeBf2XPWKxyG1SUfegDVSy9OPF8BY11Fsp9I5RP1W3T/c32KTc7zvhtAivq9mbcrBYJZhDCKpZkdTNliFQ0="
- GRADLE_OPTS="-Xms40m -Xmx3g -XX:MaxPermSize=3g"

android:
components:
Expand All @@ -25,7 +24,9 @@ before_install:
after_success:
- if [ -n "$GITHUB_API_KEY" ]; then .buildscript/deploy_alpha.sh; fi

script: "./gradlew check"
script:
- ./gradlew check assembleDebug assembleDebugAndroidTest -Dorg.gradle.jvmargs="-Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError" -Dorg.gradle.daemon=false
- .buildscript/firebase_tests.sh

branches:
except:
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<MainActivity> activityRule = new ActivityTestRule<MainActivity>(MainActivity.class, true, false) {
@Override
protected void beforeActivityLaunched() {
PrefUtils.setInitialSettings(InstrumentationRegistry.getTargetContext(), false);
}
};
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<>(MainActivity.class, true, false);

@Test
public void canHandleDevelopersGoogleChapterUri() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class MainActivityTest {
public ActivityTestRule<MainActivity> activityRule = new ActivityTestRule<MainActivity>(MainActivity.class) {
@Override
protected void beforeActivityLaunched() {
PrefUtils.setInitialSettings(InstrumentationRegistry.getTargetContext(), false);
PrefUtils.setHomeChapter(InstrumentationRegistry.getTargetContext(), CHAPTER_BRUSSELS);
}
};
Expand Down
15 changes: 15 additions & 0 deletions app/src/androidTest/java/org/gdg/frisbee/android/app/TestApp.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
19 changes: 16 additions & 3 deletions app/src/main/java/org/gdg/frisbee/android/utils/PrefUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)) {
Expand All @@ -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();
Expand Down

0 comments on commit 5a5959a

Please sign in to comment.