From 3506d699ae57dc8659ee1abe3d80a8e1b5faee0d Mon Sep 17 00:00:00 2001 From: WonderCsabo Date: Fri, 26 Jun 2015 23:11:03 +0200 Subject: [PATCH 1/7] Use Docker-based Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3ab53fb7e..b382d5833 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: java jdk: oraclejdk7 env: From 877ac04ad87c9a92f6e23dc4fcd23e57d90dd464 Mon Sep 17 00:00:00 2001 From: WonderCsabo Date: Wed, 17 Jun 2015 18:58:22 +0200 Subject: [PATCH 2/7] Enable Travis build cache --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index b382d5833..9597a798c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ sudo: false language: java +cache: + directories: + - $HOME/.m2 jdk: oraclejdk7 env: matrix: From af733c1f04ff3b043ad0b5e453c0ed316478b15c Mon Sep 17 00:00:00 2001 From: WonderCsabo Date: Sat, 6 Jun 2015 20:11:57 +0200 Subject: [PATCH 3/7] Use native Travis Android support --- .travis.yml | 80 +++++++++++------------------------------------ wait_for_emulator | 17 ---------- 2 files changed, 19 insertions(+), 78 deletions(-) delete mode 100755 wait_for_emulator diff --git a/.travis.yml b/.travis.yml index 9597a798c..f0d2b7ecb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,60 +1,27 @@ sudo: false -language: java cache: directories: - $HOME/.m2 jdk: oraclejdk7 -env: - matrix: - # android-19 is always included - - ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a -before_install: - # Install base Android SDK - - sudo apt-get update -qq - # changed install to -q instead of -qq to expose any missing packages - - if [ `uname -m` = x86_64 ]; then sudo apt-get install -q --force-yes libgd2-xpm ia32-libs ia32-libs-multiarch > /dev/null; fi - - wget http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz - - tar xzf android-sdk_r23.0.2-linux.tgz - - export ANDROID_HOME=$PWD/android-sdk-linux - - export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools - - # Maven 3.2.3 - #- wget http://www.us.apache.org/dist/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.tar.gz - #- tar xvf apache-maven-3.2.3-bin.tar.gz > /dev/null - #- export MVN_HOME=`pwd`/apache-maven-3.2.3 - #- export PATH=${MVN_HOME}/bin/:${PATH} - #- mvn --version - - # Install required components. - # For a full list, run `android list sdk -a --extended` - # Note that sysimg-19 downloads the ARM, x86 and MIPS images (we should optimize this). - # Other relevant API's: - # addon-google_apis-google-16 - # removed > /dev/null to prevent Travis timing out and ease debugging - - echo y | android update sdk --filter tools,platform-tools --no-ui --force --all - - echo y | android update sdk --filter build-tools-19.0.3 --no-ui --force --all - - echo y | android update sdk --filter build-tools-21.1.2 --no-ui --force --all - - echo y | android update sdk --filter build-tools-22.0.1 --no-ui --force --all - - echo y | android update sdk --filter $ANDROID_TARGET --no-ui --force --all - - echo y | android update sdk --filter sys-img-$ANDROID_ABI-$ANDROID_TARGET --no-ui --force --all - - echo y | android update sdk --filter extra-android-support,extra-android-m2repository --no-ui --force --all - - echo y | android update sdk --filter extra-google-m2repository --no-ui --force --all +language: android +android: + components: + - android-19 + - android-22 + - build-tools-22.0.0 + - build-tools-22.0.1 + - build-tools-21.1.2 + - sys-img-armeabi-v7a-android-22 + - extra-android-m2repository + licenses: + - android-sdk-license-5be876d5 +before_script: # Create and start emulator - - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI + - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a - emulator -avd test -no-skin -no-audio -no-window & - - # Install Android NDK 10c (not working so commented out for now) - # Note: There is now a difference between Target architecture and Platform architecture. What SHOULD they be? - #- NDK_ARCH="" - #- if [ `uname -m` = x86_64 ]; then NDK_ARCH=_64; fi - #- FILE="android-ndk-r10c-linux-x86${NDK_ARCH}.bin" - #- wget http://dl.google.com/android/ndk/${FILE} - #- chmod a+x ${FILE} - #- ./${FILE} > nul - #- export ANDROID_NDK_HOME=$PWD/android-ndk-r10c - - # Install Android NDK 10b + + # Install Android NDK 10b # Note: There is now a difference between Target architecture and Platform architecture. What SHOULD they be? - NDK_ARCH="" - NDK_PLAT="32" @@ -63,18 +30,9 @@ before_install: - wget http://dl.google.com/android/ndk/${FILE} - tar xjf ${FILE} - export ANDROID_NDK_HOME=$PWD/android-ndk-r10b - - - -# setting install to true to avoid unnecessary build -install: true -before_script: # Make sure the emulator is running. - - ./wait_for_emulator + - android-wait-for-emulator + - adb shell input keyevent 82 & -# with integration tests disabled for now since they require -# the usage of Maven Android SDK Deployer to get the -# Maven repos from the SDK deployed to the local repository -# script: mvn clean install -Dandroid.device=test -P it -script: mvn clean install -Dandroid.device=test +script: mvn clean install -Dandroid.device=test -P it diff --git a/wait_for_emulator b/wait_for_emulator deleted file mode 100755 index 317883878..000000000 --- a/wait_for_emulator +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -bootanim="" -failcounter=0 -until [[ "$bootanim" =~ "stopped" ]]; do - bootanim=`adb -e shell getprop init.svc.bootanim 2>&1` - echo "$bootanim" - if [[ "$bootanim" =~ "not found" ]]; then - let "failcounter += 1" - if [[ $failcounter -gt 3 ]]; then - echo "Failed to start emulator" - exit 1 - fi - fi - sleep 1 -done -echo "Done" From 9087b576fd0684560ce20342ef0f03f548265eb8 Mon Sep 17 00:00:00 2001 From: WonderCsabo Date: Wed, 17 Jun 2015 18:34:29 +0200 Subject: [PATCH 4/7] Change ConfigureMorseActivityTest to use Espresso --- .../morseflash-instrumentation/pom.xml | 39 ++++++++++++++ .../src/main/AndroidManifest.xml | 2 +- .../android/morseflash/AllTests.java | 33 ------------ .../ConfigureMorseActivityTest.java | 54 +++++++------------ 4 files changed, 58 insertions(+), 70 deletions(-) delete mode 100644 src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/AllTests.java diff --git a/src/test/projects/morseflash/morseflash-instrumentation/pom.xml b/src/test/projects/morseflash/morseflash-instrumentation/pom.xml index f1316b4f8..f566ed975 100644 --- a/src/test/projects/morseflash/morseflash-instrumentation/pom.xml +++ b/src/test/projects/morseflash/morseflash-instrumentation/pom.xml @@ -19,11 +19,34 @@ android provided + + com.android.support.test + runner + 0.3 + aar + com.google.android android-test provided + + com.android.support.test.espresso + espresso-core + 2.2 + aar + + + com.android.support.test + rules + 0.3 + aar + + + junit + junit + 4.12 + com.simpligility.android.morse morseflash-app @@ -69,10 +92,26 @@ + + .* + true + + + support_test + + + android-m2 + Android M2 + file://${env.ANDROID_HOME}/extras/android/m2repository + + + + + diff --git a/src/test/projects/morseflash/morseflash-instrumentation/src/main/AndroidManifest.xml b/src/test/projects/morseflash/morseflash-instrumentation/src/main/AndroidManifest.xml index a83d6a5fd..996ee6202 100644 --- a/src/test/projects/morseflash/morseflash-instrumentation/src/main/AndroidManifest.xml +++ b/src/test/projects/morseflash/morseflash-instrumentation/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ - diff --git a/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/AllTests.java b/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/AllTests.java deleted file mode 100644 index bbdfde661..000000000 --- a/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/AllTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.simpligility.android.morseflash; - -import android.test.suitebuilder.TestSuiteBuilder; -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * A test suite containing all tests for MorseFlash. - */ -public class AllTests extends TestSuite { - - public static Test suite() { - return new TestSuiteBuilder(AllTests.class) - .includeAllPackagesUnderHere() - .build(); - } -} \ No newline at end of file diff --git a/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/ConfigureMorseActivityTest.java b/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/ConfigureMorseActivityTest.java index 65a634f6c..aae571956 100644 --- a/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/ConfigureMorseActivityTest.java +++ b/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/ConfigureMorseActivityTest.java @@ -16,54 +16,36 @@ package com.simpligility.android.morseflash; -import android.app.Activity; -import android.app.Instrumentation; -import android.content.Intent; -import android.test.ActivityInstrumentationTestCase; -import android.test.ActivityInstrumentationTestCase2; +import android.support.test.rule.ActivityTestRule; +import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.LargeTest; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; -import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.typeText; +import static android.support.test.espresso.matcher.ViewMatchers.withId; import static com.github.rtyley.android.screenshot.celebrity.Screenshots.poseForScreenshot; import static com.github.rtyley.android.screenshot.celebrity.Screenshots.poseForScreenshotNamed; -import static java.lang.Thread.sleep; -/** - * Make sure that the main launcher activity opens up properly, which will be - * verified by {@link ActivityInstrumentationTestCase#testActivityTestCaseSetUpProperly}. - */ -public class ConfigureMorseActivityTest extends ActivityInstrumentationTestCase2 { - /** - * The first constructor parameter must refer to the package identifier of the - * package hosting the activity to be launched, which is specified in the AndroidManifest.xml - * file. This is not necessarily the same as the java package name of the class - in fact, in - * some cases it may not match at all. - */ - public ConfigureMorseActivityTest() { - super("com.simpligility.android.morseflash", ConfigureMorseActivity.class); - } +@RunWith(AndroidJUnit4.class) +public class ConfigureMorseActivityTest { + @Rule + public ActivityTestRule mActivityRule = + new ActivityTestRule(ConfigureMorseActivity.class); + + @Test @LargeTest public void testAppearance() throws Exception { - startActivitySync(ConfigureMorseActivity.class); - Instrumentation instrumentation = getInstrumentation(); - - sleep(500); // robotium provides neater ways of waiting for the activity to initialise - poseForScreenshot(); - instrumentation.sendStringSync("s"); + onView(withId(R.id.message)).perform(typeText("s")); poseForScreenshot(); - instrumentation.sendStringSync("o"); + onView(withId(R.id.message)).perform(typeText("o")); poseForScreenshot(); - instrumentation.sendStringSync("s"); + onView(withId(R.id.message)).perform(typeText("s")); poseForScreenshotNamed("ConfigureMorseActivity-SOS"); } - - private T startActivitySync(Class clazz) { - Intent intent = new Intent(getInstrumentation().getTargetContext(), clazz); - intent.setFlags(intent.getFlags() | FLAG_ACTIVITY_NEW_TASK); - return (T) getInstrumentation().startActivitySync(intent); - } - } \ No newline at end of file From f390c6c7669ba49f6fcc4928d6e36a053bcc4ba5 Mon Sep 17 00:00:00 2001 From: WonderCsabo Date: Wed, 17 Jun 2015 18:40:04 +0200 Subject: [PATCH 5/7] Use support_test profile in Morseflash test --- .../maven/plugins/android/sample/MorseflashSampleIT.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/simpligility/maven/plugins/android/sample/MorseflashSampleIT.java b/src/test/java/com/simpligility/maven/plugins/android/sample/MorseflashSampleIT.java index 607707689..162f8a659 100644 --- a/src/test/java/com/simpligility/maven/plugins/android/sample/MorseflashSampleIT.java +++ b/src/test/java/com/simpligility/maven/plugins/android/sample/MorseflashSampleIT.java @@ -48,6 +48,7 @@ public void buildDeployAndRun() throws Exception { File basedir = resources.getBasedir( "morseflash" ); MavenExecutionResult result = mavenRuntime .forProject(basedir) + .withCliOptions("-Psupport_test") .execute( "clean", PluginInfo.getQualifiedGoal( "undeploy" ), "install" ); From cd916817577ea1b3df58d94cb8af9a415c9c927a Mon Sep 17 00:00:00 2001 From: WonderCsabo Date: Fri, 26 Jun 2015 20:16:52 +0200 Subject: [PATCH 6/7] Disable screen lock programatically --- .../src/main/AndroidManifest.xml | 4 ++ .../src/main/AndroidManifest.xml | 2 +- .../morseflash/ScreenUnlockerTestRunner.java | 47 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/ScreenUnlockerTestRunner.java diff --git a/src/test/projects/morseflash/morseflash-app/src/main/AndroidManifest.xml b/src/test/projects/morseflash/morseflash-app/src/main/AndroidManifest.xml index f7da40fe4..e76a33d5a 100644 --- a/src/test/projects/morseflash/morseflash-app/src/main/AndroidManifest.xml +++ b/src/test/projects/morseflash/morseflash-app/src/main/AndroidManifest.xml @@ -4,6 +4,10 @@ android:versionCode="1" android:versionName="1.0.0-SNAPSHOT"> + + + + diff --git a/src/test/projects/morseflash/morseflash-instrumentation/src/main/AndroidManifest.xml b/src/test/projects/morseflash/morseflash-instrumentation/src/main/AndroidManifest.xml index 996ee6202..579f75c3a 100644 --- a/src/test/projects/morseflash/morseflash-instrumentation/src/main/AndroidManifest.xml +++ b/src/test/projects/morseflash/morseflash-instrumentation/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ - diff --git a/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/ScreenUnlockerTestRunner.java b/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/ScreenUnlockerTestRunner.java new file mode 100644 index 000000000..9053222f4 --- /dev/null +++ b/src/test/projects/morseflash/morseflash-instrumentation/src/main/java/com/simpligility/android/morseflash/ScreenUnlockerTestRunner.java @@ -0,0 +1,47 @@ +package com.simpligility.android.morseflash; + +import android.app.KeyguardManager; +import android.content.Context; +import android.os.PowerManager; +import android.support.test.runner.AndroidJUnitRunner; + +import static android.content.Context.KEYGUARD_SERVICE; +import static android.content.Context.POWER_SERVICE; +import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP; +import static android.os.PowerManager.FULL_WAKE_LOCK; +import static android.os.PowerManager.ON_AFTER_RELEASE; + +/** + * Instrumentation which unlocks the screen before running any test. + * This needs the following permissions in the application manifest: + * + *
+ *     
+ *     
+ * 
+ * + * Adapted from https://github.com/JakeWharton/u2020/blob/master/src/androidTestInternal/java/com/jakewharton/u2020/U2020TestRunner.java. + */ +public final class ScreenUnlockerTestRunner extends AndroidJUnitRunner { + + @Override + public void onStart() { + runOnMainSync(new Runnable() { + @SuppressWarnings("deprecation") + // We don't care about deprecation here. + public void run() { + Context app = getTargetContext().getApplicationContext(); + + String name = ScreenUnlockerTestRunner.class.getSimpleName(); + // Unlock the device so that the tests can input keystrokes. + KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE); + keyguard.newKeyguardLock(name).disableKeyguard(); + // Wake up the screen. + PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE); + power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name).acquire(); + } + }); + + super.onStart(); + } +} \ No newline at end of file From be297ba10bd9b73f148e74eb76778a74a6337813 Mon Sep 17 00:00:00 2001 From: WonderCsabo Date: Fri, 26 Jun 2015 23:21:11 +0200 Subject: [PATCH 7/7] Update changelog for #641 --- src/site/asciidoc/changelog.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/site/asciidoc/changelog.adoc b/src/site/asciidoc/changelog.adoc index 0103afcc1..2ab73f02e 100644 --- a/src/site/asciidoc/changelog.adoc +++ b/src/site/asciidoc/changelog.adoc @@ -2,6 +2,10 @@ == 4.3.1 or higher - upcoming +* Fix continuous integration(use Travis Android support and enable/update ITs) +** See https://github.com/simpligility/android-maven-plugin/pull/641 +** contributed by Csaba Kozák https://github.com/WonderCsabo + Planned changes: * migrate more tests to be instrumentation tests with example projects