Testing with emulator.wtf
How to run tests using emulators from emulator.wtf
Configuring emulator.wtf API token
In order to use emulator.wtf service for app testing, you need to obtain an emulator.wtf API token and save it as an environment variable in Codemagic.
- Open your Codemagic app settings, and go to the Environment variables tab.
- Enter the desired Variable name, e.g.
EW_API_TOKEN. - Copy and paste the content of the token as Variable value.
- Enter the variable group name, e.g. emulatorwtf. Click the button to create the group.
- Make sure the Secret option is selected.
- Click the Add button to add the variable.
You can then import the token in your workflow:
workflows:
android-build:
environment:
groups:
- emulatorwtf # adds EW_API_TOKEN to the workflowRunning tests
Add the following snippet under your workflow after the Gradle build step. Update the --app and --test paths according to your build if necessary.
scripts:
- name: Test
script: |
ew-cli \
--app app/build/outputs/apk/debug/app-debug.apk \
--test app/build/outputs/apk/androidTest/app-debug-androidTest.apk \
--outputs-dir results
test_report: results/**/*.xmlCapturing logcat
Add the following to your workflow to capture logcat output from the emulator during the test run:
artifacts:
- results/**/logcat.txtRunning tests with coverage
Add --with-coverage to the ew-cli script to capture coverage during the test run:
scripts:
- name: Test
script: |
ew-cli \
--app app/build/outputs/apk/debug/app-debug.apk \
--test app/build/outputs/apk/androidTest/app-debug-androidTest.apk \
--with-coverage \
--outputs-dir results
test_report: results/**/*.xmlRunning tests in parallel
Add --num-shards <NUMBER> to run tests in parallel shards, here’s an example to shard tests to 4:
scripts:
- name: Test
script: |
ew-cli \
--app app/build/outputs/apk/debug/app-debug.apk \
--test app/build/outputs/apk/androidTest/app-debug-androidTest.apk \
--num-shards 4 \
--outputs-dir results
test_report: results/**/*.xmlRunning tests with orchestrator
Add --use-orchestrator to run tests with Android Test Orchestrator
(more infos here):
scripts:
- name: Test
script: |
ew-cli \
--app app/build/outputs/apk/debug/app-debug.apk \
--test app/build/outputs/apk/androidTest/app-debug-androidTest.apk \
--use-orchestrator \
--outputs-dir results
test_report: results/**/*.xmlFurther information
There are more options available like pulling directories from the emulator after tests have finished, running on various device models, etc. Check the emulator.wtf docs for more ew-cli options to customize your test run.