Skip to content

Commit

Permalink
Merge pull request #641 from WonderCsabo/travisAndroid
Browse files Browse the repository at this point in the history
Use Travis Android support
  • Loading branch information
mosabua committed Jun 26, 2015
2 parents b38cc91 + be297ba commit 9326ba3
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 148 deletions.
84 changes: 23 additions & 61 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,27 @@
language: java
sudo: false
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"
Expand All @@ -59,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
4 changes: 4 additions & 0 deletions src/site/asciidoc/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
android:versionCode="1"
android:versionName="1.0.0-SNAPSHOT">

<!-- these are only needed for the instrumentation test-->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19"/>
<application android:name="MorseFlashApplication" android:debuggable="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="ConfigureMorseActivity" android:label="@string/app_name">
Expand Down
39 changes: 39 additions & 0 deletions src/test/projects/morseflash/morseflash-instrumentation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,34 @@
<artifactId>android</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.android.support.test</groupId>
<artifactId>runner</artifactId>
<version>0.3</version>
<type>aar</type>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android-test</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.android.support.test.espresso</groupId>
<artifactId>espresso-core</artifactId>
<version>2.2</version>
<type>aar</type>
</dependency>
<dependency>
<groupId>com.android.support.test</groupId>
<artifactId>rules</artifactId>
<version>0.3</version>
<type>aar</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.simpligility.android.morse</groupId>
<artifactId>morseflash-app</artifactId>
Expand Down Expand Up @@ -69,10 +92,26 @@
<!--<package>your.package.name</package>-->
<!--</packages>-->
</test>
<excludeJarResources>
<excludeJarResource>.*</excludeJarResource>
</excludeJarResources>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>support_test</id>
<repositories>
<repository>
<id>android-m2</id>
<name>Android M2</name>
<url>file://${env.ANDROID_HOME}/extras/android/m2repository</url>
</repository>
</repositories>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<application>
<uses-library android:name="android.test.runner"/>
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
<instrumentation android:name="com.simpligility.android.morseflash.ScreenUnlockerTestRunner"
android:targetPackage="com.simpligility.android.morseflash"
android:label="Tests for MorseFlash."/>
</manifest>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigureMorseActivity> {

/**
* 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<ConfigureMorseActivity> mActivityRule =
new ActivityTestRule<ConfigureMorseActivity>(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 extends Activity> T startActivitySync(Class<T> clazz) {
Intent intent = new Intent(getInstrumentation().getTargetContext(), clazz);
intent.setFlags(intent.getFlags() | FLAG_ACTIVITY_NEW_TASK);
return (T) getInstrumentation().startActivitySync(intent);
}

}
Original file line number Diff line number Diff line change
@@ -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 <b>application</b> manifest:
*
* <pre>
* <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
* <uses-permission android:name="android.permission.WAKE_LOCK"/>
* </pre>
*
* 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();
}
}
17 changes: 0 additions & 17 deletions wait_for_emulator

This file was deleted.

0 comments on commit 9326ba3

Please sign in to comment.