Issue
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?
Solution
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" />
Answered By - bananamuff1n
Answer Checked By - Candace Johnson (JavaFixing Volunteer)