For my instrumentation tests I was using
@RunWith(AndroidJUnit4.class)
from
import androidx.test.runner.AndroidJUnit4;
Solution
Add this line in to build.gradle: androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Change AndroidJUnit4 to AndroidJUnit4ClassRunner in the test class
Warning
I got the same error, but the following solution failed for me:
File -> Invalidate Caches..., and select Invalidate and Restart