When I run instrumentation tests from within Android Studio, I see that the app remains on the device afterwards. But I can't figure out to do this from the command line with gradlew. My intention is to run tests that save screenshots in e.g /data/data/MyApp/cache/screenshots and download these with adb pull
afterwards.
./gradlew connectedAndroidTest
causes the app to be uninstalled. I also tried
./gradlew connectedAndroidTest -x uninstallAndroidTest
but that didn't make any difference. What's causing the uninstallation, and how can I avoid it?
Use the command ./gradlew test to run all tests.
The Espresso Test Recorder tool lets you create UI tests for your app without writing any test code. By recording a test scenario, you can record your interactions with a device and add assertions to verify UI elements in particular snapshots of your app.
Instrumented UI tests in Android Studio To run instrumented UI tests using Android Studio, you implement your test code in a separate Android test folder - src/androidTest/java . The Android Plug-in for Gradle builds a test app based on your test code, then loads the test app on the same device as the target app.
I solved this by letting gradle only build the apk, and then handling the install/test/uninstall work with adb. Here's an approximation of my script.
PKGNAME=com.corp.app ./gradlew assembleAndroidTest adb install -r app/build/outputs/apk/app-debug.apk adb install -r app/build/outputs/apk/app-debug-androidTest-unaligned.apk adb shell am instrument -w ${PKGNAME}.test/android.support.test.runner.AndroidJUnitRunner [ -d screenshots ] || mkdir screenshots adb pull /data/data/${PKGNAME}/cache/screenshots screenshots # Now we can uninstall. adb uninstall ${PKGNAME}.test adb uninstall ${PKGNAME}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With