Obviously I need the correct import statment to solve this problem. According to the docs for AndroidJUnit4, this should be
import android.support.test.runn
The common cause of this problem is that when adding below dependency:
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
This is a correct dependency if you are going to use instrumented tests (tests in the androidTest
java package)
But for implementing local unit tests (tests in test
java package) while using above mentioned dependency; then you'll face Cannot resolve symbol 'AndroidJUnit4'
That is because androidTestImplementation
directive is used to import libraries in instrumented tests, but not in the local JVM/unit tests.
If you want to use AndroidJUnit4
in a local JVM/unit test, then use below dependency instead
testImplementation 'androidx.test.ext:junit:1.1.1'
The same thing applies if you add the latter dependency while using AndroidJUnit4
in instrumented test, you will also get Cannot resolve symbol 'AndroidJUnit4'
; because you're using the wrong directive.