androidandroid-studioinstrumentation

Android Instrumentation Tests cancelled but run on device


In my project where I was able run instrumentation tests successfully, after upgrading Android Studio to Giraffe, now the instrumentation tests cannot connect to the test device and the tests are cancelled upon launch.

When I run any tests, it gives warning saying tests are cancelled, and previously the adb command was resulting in 'Connected' state, now it does not appear as well.

Finally, the test runs in my device even though the Android Studio shows them as cancelled. Also, if I run the; adb shell am instrument -w -m --no-window-animation -e debug false -e class 'com..sample.tests.PoiInteractionTests#test_rich_poi_213' com..demo.mock.prod.test/android.support.test.runner.AndroidJUnitRunner

command on terminal, I see that my tests run successfully in the terminal.

I tried to upgrade the gradle plugin to 7.4.2. I tried to Invalidate Caches and restart Android Studio. None of them worked. The end result is like this;

enter image description here


Solution

  • First configure Android Studio to Run Android Instrumention Tests using Gradle. like it is suggested here. https://stackoverflow.com/a/77271279/10517151

    Then upgrade your Gradle and Android Gradle Plugin versions preferably to the latest stable.