Android : Espresso Test kit - How to run espresso tests on already existing app on emulator

android, android-espresso

Solution

You could install your apks using ADB and then start the tests manually:

$ adb install myapp.apk (1)
$ adb install myapp-androidTest-unaligned.apk (2)
$ adb shell am instrument -w com.myapp.test/android.support.test.runner.AndroidJUnitRunner (3)

- (1) upload your app apk

- (2) upload your test apk apk

- (3) be sure to use your test apk's package name which is usually your app package name, post-fixed with `.test`. Also you have to use the fully qualified test runner. This is whatever you specified as the `testInstrumentationRunner` in your build.gradle file.

To answer your question, you may not need to do steps 1 and 2 if the apk and test apk are already on your device (perhaps by previously running `./gradlew connectedAndroidTest`)

Have a look in this Android doc page, it tells a little bit more about the adb shell am instrument commend.

Problem

I want to install android app from local driver on emulator and run tests of espresso on already existing app. Is there any way to skip installation of app in espresso tests?

Original source