12

My Pixel 4a was upgraded to Android 12 and now, when I try to run an Espresso test on that device, no tests run. Android Studio says "Tests Passed 0 passed". No tests ran. Tests still run as expected on an Android 11 device.

My test method is annotated with org.junit.Test. My test class is annotated with androidx.test.filters.LargeTest.

I made sure to upgrade Android Studio. I updated compileSdkVersion and targetSdkVersion to 31 in build.gradle. I checked my test dependencies and updated them to the following versions:

junit:junit:4.13.2
androidx.test.ext:junit-ktx:1.1.3
androidx.test:runner:1.4.0
androidx.test:rules:1.4.0
androidx.test.uiautomator:uiautomator:2.2.0
androidx.test.espresso:espresso-core:3.4.0
androidx.work:work-testing:2.7.0

After all these changes, the problem is still there, and I've also seen it on AVDs.

Has anybody else experienced this issue?

Denis
  • 133
  • 1
  • 7
  • Commenting "execution 'ANDROIDX_TEST_ORCHESTRATOR'" fixed the problem on our side. See https://github.com/vector-im/element-android/pull/4433/commits/0ecf1a4ffade32ec54113b7002148edbfb2cb41a – bma350 Nov 10 '21 at 18:44
  • 1
    Not only on 31, but 30 has the same issue with AS Arctic Fox. Not known why. – BollMose Nov 22 '21 at 02:02
  • See also https://stackoverflow.com/questions/72114551/android-studio-testing-shows-test-results-0-0-how-can-i-begin-the-tests. – CoolMind Jan 11 '23 at 07:09

2 Answers2

12

How I resolved Android 12.

If you want to use test orchestrator

Make sure you have the latest orchestrator and test runner versions.

androidTestUtil 'androidx.test:orchestrator:1.4.1'
androidTestImplementation 'androidx.test:runner:1.4.0'

make sure this is in your testOptions of the app/build.gradle.

execution 'ANDROIDX_TEST_ORCHESTRATOR'

Or, if you don't want to use test orchestrator

Remove the following line from the testOptions of the app/build.gradle.

 execution 'ANDROIDX_TEST_ORCHESTRATOR'
 

How I resolved Android 11.

(If you're interested in running orchestrator on Android 12, do the below step in addition to the first step above)

Create an AndroidManifest.xml in the androidTest folder and add the below query permission to resolve 'no tests found' by allowing the orchestrator package to communicate with the test package

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="your.package.name">

<!-- This Manifest will only apply changes to androidTest builds -->

<queries>
    <package android:name="androidx.test.orchestrator.OrchestratorService"/>
</queries>

<application android:forceQueryable="true" />
Michael Osofsky
  • 11,429
  • 16
  • 68
  • 113
bananamuff1n
  • 136
  • 1
  • 4
  • I have been at this for 4 hours and you just solved this issue for me. Thank you for your detailed and very helpful answer! – Akres Jan 05 '22 at 17:22
  • Perfect. This is exactly what I had been looking for. Thank you! – Denis Jan 27 '22 at 17:55
  • 1
    Bonus bit of information, Android docs say which versions are available for each artifact. This was useful for me since I had mistakenly expected 1.4.1 to be available for everything. https://developer.android.com/jetpack/androidx/releases/test – Zeek Aran Oct 11 '22 at 18:19
0

you can install the orchestrator.apk and test-server.apk with following way

adb install --force-queryable orchestrator.apk

adb install --force-queryable test-services.apk

No need to change the manifest file for that.

Varun RTR
  • 29
  • 3