Reputation: 51
we are using CircleCI for our Android project. I wonder whether CircleCI can support unit test/espresso test. I could not find too much useful information on internet.
Upvotes: 3
Views: 1345
Reputation: 329
I am running Android UI tests on CircleCI MacOS executor. Here is my configuration:
version: 2
reference:
## Constants
gradle_cache_path: &gradle_cache_path
gradle_cache-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
workspace: &workspace
~/src
## Configurations
android_config: &android_config
working_directory: *workspace
macos:
xcode: "9.4.0"
shell: /bin/bash --login -eo pipefail
environment:
TERM: dumb
JVM_OPTS: -Xmx3200m
## Cache
restore_gradle_cache: &restore_gradle_cache
restore_cache:
key: *gradle_cache_path
save_gradle_cache: &save_gradle_cache
save_cache:
key: *gradle_cache_path
paths:
- ~/.gradle
## Dependency Downloads
download_android_dependencies: &download_android_dependencies
run:
name: Download Android Dependencies
command: ./gradlew androidDependencies
jobs:
ui_test:
<<: *android_config
steps:
- checkout
- run:
name: Setup environment variables
command: |
echo 'export PATH="$PATH:/usr/local/opt/node@8/bin:${HOME}/.yarn/bin:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin:/usr/local/share/android-sdk/tools/bin"' >> $BASH_ENV
echo 'export ANDROID_HOME="/usr/local/share/android-sdk"' >> $BASH_ENV
echo 'export ANDROID_SDK_HOME="/usr/local/share/android-sdk"' >> $BASH_ENV
echo 'export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"' >> $BASH_ENV
echo 'export QEMU_AUDIO_DRV=none' >> $BASH_ENV
echo 'export JAVA_HOME=/Library/Java/Home' >> $BASH_ENV
- run:
name: Install Android sdk
command: |
HOMEBREW_NO_AUTO_UPDATE=1 brew tap homebrew/cask
HOMEBREW_NO_AUTO_UPDATE=1 brew cask install android-sdk
- run:
name: Install emulator dependencies
command: (yes | sdkmanager "platform-tools" "platforms;android-26" "extras;intel;Hardware_Accelerated_Execution_Manager" "build-tools;26.0.0" "system-images;android-26;google_apis;x86" "emulator" --verbose) || true
- *restore_gradle_cache
- *download_android_dependencies
- *save_gradle_cache
- run: avdmanager create avd -n Pixel_2_API_26 -k "system-images;android-26;google_apis;x86" -g google_apis -d "Nexus 5"
- run:
name: Run emulator in background
command: /usr/local/share/android-sdk/tools/emulator @Pixel_2_API_26 -skin 1080x2066 -memory 2048 -noaudio
background: true
- run:
name: Run Tests
command: ./gradlew app:connectedAndroidTest
https://gist.github.com/DoguD/58b4b86a5d892130af84074078581b87
https://github.com/c2mInc/Circle-CI-Instrumentation-Tests-for-Android
I hope it helps
Upvotes: 0
Reputation: 119
I got my CircleCI build to run both espresso and unit test below is my circle.yml file
general:
artifacts:
- /home/ubuntu/PopularMovies/app/build/outputs/apk/
machine:
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
dependencies:
override:
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,android-23,extra-android-m2repository,extra-google-m2repository,extra-google-google_play_services,extra-android-support
- echo y | android update sdk --no-ui --all --filter build-tools-23.0.3
test:
override:
# perform unit tests
- ./gradlew tesMockDebugUnitTest
# Save test reports
- mkdir -p $CIRCLE_TEST_REPORTS/reports/unit-tests
- cp -avr app/build/reports/tests/mockDebug/ $CIRCLE_TEST_REPORTS/reports/unit-tests
- mkdir -p $CIRCLE_TEST_REPORTS/junit/
- find . -type f -regex ".*/build/test-results/mockDebug/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
# start the emulator
- emulator -avd circleci-android22 -no-audio -no-window:
background: true
parallel: true
# wait for it to have booted
- circle-android wait-for-boot
# unlock the emulator screen
- sleep 30
- adb shell input keyevent 82
# run tests against the emulator.
- ./gradlew connectedMockDebugAndroidTest -PdisablePreDex
# Copying the test reports
- mkdir -p $CIRCLE_TEST_REPORTS/reports/functional-tests
- cp -avr app/build/reports/androidTests/connected/flavors/MOCK/ $CIRCLE_TEST_REPORTS/reports/functional-tests
You can view my CircleCI build at https://circleci.com/gh/adityam7/PopularMovies/25
I hope this helps
Upvotes: 1
Reputation: 2065
Yes, CircleCI can support running unit and espresso tests by configuring your circle.yml
test
./gradlew test
Espresso tests are a little more involved because you need to run these tests on an android emulator.
test:
pre:
# start the emulator
- emulator -avd circleci-android22 -no-audio -no-window:
background: true
parallel: true
# wait for it to have booted
- circle-android wait-for-boot
# unlock the emulator screen
- sleep 30
- adb shell input keyevent 82
override:
# run tests against the emulator.
- ./gradlew connectedAndroidTest -PdisablePreDex
Upvotes: 3
Reputation: 306
Put following in your circle.yml, then at least your unit tests should run (I don't have espresso tests in my project yet)
test:
override:
- export TERM="dumb"; if [ -e ./gradlew ]; then ./gradlew test;else gradle test;fi
- cp -r app/build/test-results/* $CIRCLE_TEST_REPORTS
Last line copies your test result so CircleCI can analyze them. Be sure to provide proper path to /build directory
Refer to CircleCI documentation for more information and for tests on running emulator - https://circleci.com/docs/android
Upvotes: 0