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
Add this dependency in your build.gradle file:
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Update the end version (1.1.1
) with the latest version released.
I made the mistake to put the test classes at src/test. After moving them to src/androidTest/java/ the dependency was resolved.
I solved the problem by making a small change in the app's build.gradle file. In the dependencies { ... }
section, make sure to include the following line:
debugImplementation 'com.android.support.test:runner:1.0.1'
or whatever version is the newest at that point (...Compile
is deprecated and has been replaced by ...Implementation
). Note the use of debugImplementation
. Android Studio suggested auto-including it with androidTestImplementation
, which didn't work.
I found out how to change it from test to debug by looking in Project Structure under Dependencies of the app module, where you can change the scope of each dependency, see below.
put this code in your Dependencies
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
Move the test class to src/androidTest/java/. Then dependency will resolve.
Make sure your app in debug build variant. Go to Build > Select Build Variant... and the following should show up: