Run UI automation tests with gradle without uninstalling Run UI automation tests with gradle without uninstalling android android

Run UI automation tests with gradle without uninstalling


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 assembleAndroidTestadb install -r app/build/outputs/apk/app-debug.apkadb install -r app/build/outputs/apk/app-debug-androidTest-unaligned.apkadb shell am instrument -w ${PKGNAME}.test/android.support.test.runner.AndroidJUnitRunner[ -d screenshots ] || mkdir screenshotsadb pull /data/data/${PKGNAME}/cache/screenshots screenshots# Now we can uninstall.adb uninstall ${PKGNAME}.testadb uninstall ${PKGNAME}


I didn't find the way out of this problem. Looks like there is no way to run instrumentation test without uninstalling. You can use gradle commands to build and install your app and testApp. It is a better way to use these commamds because apps will be installed on all connected devices.

gradlew installVersionDebuggradlew installVersionDebugAndroidTestadb shell am instrument -w -r -e debug false -e class com.example.android.EspressoUITest {PKGNAME}.test/android.support.test.runner.AndroidJUnitRunner

But there is still a problem with reports. You can use custom testRunner to generate a JUnit style XML report. Such report could be converted to HTML format with common approach.