Travis-CI and Android JUnit Tests - android

I am having a difficult time getting Travis-CI to run my unit tests. The following is my travis.yml code. Let me know if you need more information!
language: android
jdk: oraclejdk8
sudo: false
android:
components:
- platform-tools
- tools
- build-tools-24.0.2
- android-22
- android-24
- sys-img-armeabi-v7a-android-22
- extra-android-m2repository
before_script:
# Create and start emulator
- echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- ./gradlew connectedAndroidTest

I need more information to understand your specific issue. I'll update my answer if you do it.
The best would be that you share a link to a public travis-ci build, a log or a complert explanation.
Your travis.yml seems correct, perhaps you are trying to run unit tests not instrumentation tests:
script:
- ./gradlew test
I also would add an extra tools option because the Travis-ci VMs are so outdated and you need to run a chain between tools and platform-tools to get the latest versions due to dependencies:
android:
components:
- tools
- platform-tools
- tools
Verify your Espresso configuration if you re trying to run Android Tests and check this guide.

Related

How to know the exact error from Travis build

Currently, I am facing a travis CI build error in my repository here, and I'd really like to know the exact issue as connectedCheck only outputs
Tests on test(AVD) - 5.1.1 failed: Instrumentation run failed due to 'java.lang.NullPointerException'
in Travis, and the tests are passing just fine in my own machine.
This is my current .travis.yml :
sudo: required
language: android
jdk: oraclejdk8
env:
global:
- ANDROID_TARGET=android-22
- ANDROID_ABI=armeabi-v7a
android:
components:
- tools
- platform-tools
- build-tools-27.0.3
- android-27
- android-22
- extra-android-m2repository
- sys-img-${ANDROID_ABI}-${ANDROID_TARGET}
licenses:
- 'android-sdk-preview-license-52d11cd2'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'
before_script:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
- ./build.sh
- ./gradlew connectedCheck coveralls
on:
tags: true
I want to know how to get a more detailed error message (e.g. line number).
Well, it's right there in logs, according to travis job, here's the test which is failing test_shouldConvertMonthsToYears due to java.lang.NullPointerException.
Hope it helps.

Travis CI with Android Lib - No compatible devices connected

I'm currently trying to get a travis.yml that works for Android 24 / build tools 24.0.3 and having some trouble.
I have the following for my travis.yml:
language: android
sudo: required
jdk: oraclejdk8
cache:
directories:
- ${TRAVIS_BUILD_DIR}/gradle/caches/
- ${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/
env:
global:
- ANDROID_API_LEVEL=24
- ANDROID_BUILD_TOOLS_VERSION=24.0.3
- ANDROID_ABI=armeabi-v7a
- ANDROID_TAG=google_apis
- ADB_INSTALL_TIMEOUT=20 # minutes (2 minutes by default)
android:
components:
- tools # to get the new `repository-11.xml`
- platform-tools
- tools # to install Android SDK tools 25.1.x
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
- android-$ANDROID_API_LEVEL
# For Google APIs
- addon-google_apis-google-$ANDROID_API_LEVEL
# Support library
- extra-android-support
# Latest artifacts in local repository
- extra-google-m2repository
- extra-android-m2repository
# Specify at least one system image
- sys-img-armeabi-v7a-google_apis-$ANDROID_API_LEVEL
before_script:
- echo no | android create avd --force -n test -t "android-"$ANDROID_API_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- emulator -avd test -no-skin -no-window &
- android-wait-for-emulator
script:
- ./gradlew clean jacocoDebugTestReport
My current issue is that I keep getting:
: No compatible devices connected.[TestRunner] FAILED Found 1 connected device(s), 0 of which were compatible. :app:connectedDebugAndroidTest FAILED
or:
No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself.
which are two completely separate error states.
Does anyone see anything glaringly wrong or incorrect about my travis.yml that could help explain why it's not working.
Add travis_wait followed by the desired minutes to wait to fix the second issue.
before_script:
- echo no | android create avd --force -n test -t "android-"$ANDROID_API_LEVEL --abi $ANDROID_ABI --tag $ANDROID_TAG
- emulator -avd test -no-skin -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- travis_wait 20 ./gradlew clean jacocoDebugTestReport
If you fix the first issue, probably you wont need the previous solution.
The line below is normally necessary, I didn't test it on android-24 and I would need to see a full log
- adb shell input keyevent 82 &
As a workaround, I would use a lower API level as suggested here until you find a better solution.
I have spent a lot of free time the last two years trying to find solutions to this type of issues and the best you can do is to use ci builds for lower APIs and devices or local tests for recent APIs.
The benefits of using latest APIs are not enough if you consider the time required to solve issues.
Elaborating on what Ardock posted, I was able to get around my issue by lowering the emulators SDK level. My working travis.yml is:
language: android
jdk: oraclejdk8
sudo: false
android:
components:
- platform-tools
- tools
- build-tools-24.0.3
- android-22
- android-24
- sys-img-armeabi-v7a-android-22
- extra-android-m2repository
- extra-android-support
- extra-google-m2repository
before_script:
# Create and start emulator
- echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script: ./gradlew clean connectedAndroidTest -PdisablePreDex --stacktrace
It's not super elegant having to download and install multiple SDKs, but https://github.com/isuPatches/WiseFy/commits/master
and https://travis-ci.org/isuPatches/WiseFy/builds show that it's working.

Android Espresso tests on Travis-CI

I currently have problems running Espresso tests on Travis-CI due to NoMatchingViewException, while running them locally works fine.
It doesnt seem like my .travis.yml has any problems, cause I've checked some other repositories with travis+espresso and it's quite similar.
language: android
jdk: oraclejdk8
sudo: false
env:
global:
- ANDROID_TARGET=android-19
- ANDROID_ABI=armeabi-v7a
android:
components:
# Update Android SDK Tools
- tools
- platform-tools
- build-tools-23.0.3
- android-23
# Support library
- extra-android-support
- extra-google-google_play_services
- extra-android-m2repository
- extra-google-m2repository
- sys-img-${ANDROID_ABI}-${ANDROID_TARGET}
before_script:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script:
- ./gradlew connectedAndroidTest jacocoTestReport
after_success:
- bash <(curl -s https://codecov.io/bash)
In my tests I just make calls like this, and everything is fine
onView(withId(R.id.email_edittext)).check(matches(hasErrorText(text)))
But on Travis-CI I still got failed tests
com.tests.LoginTest > test_invalidPassword[test(AVD) - 4.4.4] FAILED
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: mob.prokky.gameshare:id/email_edittext
Full Travis-CI log available here while the full tests are on github
I posted the issue in the travis git account
It looks like issue with creating emulator for the tests

TravisCI Android build fails only on CI not locally

I have got a strange error and cannot find a solution:
* What went wrong:
Execution failed for task ':app:compileDebugAndroidTestGroovy'.
> Unable to load class de.rheinfabrik.mvvm_example.activities.DetailsActivity due to missing dependency android/support/v4/view/LayoutInflaterFactory
But it´s impossible. This project works locally. Also the dependency is there.
Here my .travis.yml
language: android
jdk: oraclejdk8
env:
matrix:
- ANDROID_TARGET=android-22 ANDROID_ABI=armeabi-v7a
global:
- TERM=dumb
android:
components:
- build-tools-21.1.2
- android-22
- sys-img-armeabi-v7a-android-22
- extra
# Emulator Management: Create, Start and Wait
before_script:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
script: cd MVVM-Example && ./gradlew app:connectAndroidTest --stacktrace -PdisablePreDex
Anyone have an idea why the dependency LayoutInflaterFactory is missing?
https://travis-ci.org/AHarazim/android-mvvm-example
Try
- build-tools-22.0.1
http://developer.android.com/tools/revisions/build-tools.html
Build Tools, Revision 22.0.0 (March 2015) Added support for Android
5.1 (API level 22).
And I think that is connectedAndroidTest.
Update, try to get latest tools versions, Travis-ci reverted the last VM update, good luck, if this doesn't work, I don't know another possible reason:
language: android
android:
components:
- platform-tool
- tool
- android-22
- build-tools-22.0.1
- extra-android-m2repository
- extra-google-m2repository
- sys-img-armeabi-v7a-android-22
Update2: I forked your project, tried my suggestions and it didn't work. But I followed a discussion about to add
retrolambda {
jvmArgs '-noverify'
}
As you already did. And there was this variant, I didn't read it and rushed to the solution and works :)
script:
- cd MVVM-Example
- ./gradlew prepareDebugDependencies
- ./gradlew assembleDebug # you can run clean before assemble
- ./gradlew app:connectedAndroidTest --info
I'm not familiar with this retrolambda stuff, please explain the solution for other if it works for you, I thought that it was a simple travis issue.

Android emulator on Travis CI showing com.android.builder.testing.ConnectedDevice > hasTests[test(AVD) - 4.4.2] FAILED even though tests present

I've read through com.android.builder.testing.ConnectedDevice > hasTests[test(AVD) - 5.0] FAILED and I am having a very similar problem. Unfortunately, it's very difficult to discern what the actual solution to that problem was, given all of the discussion the solution author gave.
Essentially, I have the following .travis.yml file:
language: android
android:
components:
- build-tools-21.1.0
- android-19
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
- addon-google_apis-google-19
- addon-google_apis-google-21
- sys-img-armeabi-v7a-android-19
before_script:
- echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- cat `which android-wait-for-emulator`
- android-wait-for-emulator
- adb shell input keyevent 82 &
script: ./gradlew clean build connectedCheck
When I push, and travis builds the appropriate .apk, I end up with the following log: http://pastebin.com/LVw5rG58
If I run ./gradlew clean build installDebug, the build turns out fine, so it doesn't appear to be an issue with the timeout being too short in the android-wait-for-emulator script (also, it's using the newer version, I've checked - see the cat which android-wait-for-emulator command in the .travis.yml.
Additionally, I do have a single test in my source repository, and running ./gradlew clean build connectedCheck on my local development machine (with a phone attached) works fine.
This just started happening since I updated gradle to 2.2.1 and updated the build tools to 21.1.0. However, I have another project using the exact same .travis.yml that isn't failing for some reason.
Edit:
My application has the following directory structure:
wagebase-android/
- WageBase/
- src/
- androidTest/
- java/
- com.thisclicks.wagebase/ <- Test Sources
- main/
- java/
- com.thisclicks.wagebase/ <- App sources
Edit:
It appears that if I run this on a local emulator, it also fails with the same error. I used the same configuration as in Travis, i.e.:
$ echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a
$ emulator -avd test -no-skin -no-audio -no-window &
$ adb wait-for-device
$ ./gradlew connectedCheck
About Unable to find instrumentation target package: com.thisclicks.wagebase:
If wagebase is a Project Library, check the first response, otherwise the second response here:
unable-to-find-instrumentation-target-package-com-xyz.
You have to create and setup an Application Project that depends on
the Library Project, in order to test the Library Project.
When you create android test project remember to set good target
package
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test" <-------------------
If you run gradle installDebug --debug you'll know more about the error (share the log here), perhaps an installation issue. And you can show androidTest logs as I do here, line 3848
cat ${TRAVIS_BUILD_DIR}/*/build/outputs/androidTest-results/connected/*
About dependencies, I think that you don't need extra-google-google_play_services included in extra-google-m2repository. You can check a working travis.yml file for google apis here.
android:
components:
- build-tools-21.1.2
- android-21
- addon-google_apis-google-21
- extra-google-m2repository
- extra-android-m2repository
- sys-img-armeabi-v7a-addon-google_apis-google-21
before_install:
- echo no | android create avd --force -n test -t "Google Inc.:Google APIs:21" --abi google_apis/armeabi-v7a

Categories

Resources