Reputation: 463
I have added below dependencies in gradle:
But still ActivityTestRule can not be imported, showing error
Upvotes: 1
Views: 3402
Reputation: 540
For AndroidX
Note: Answer give by Rapunzel Van Winkle is correct and works but androidx we have to use following dependencies,
Add in app level gradle
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
Check different dependencies related to AndroidX Test official documentation
Upvotes: 1
Reputation: 5500
It looks like you're using the old dependencies from Espresso 2.2.2
. For the current version (Espresso 3.0.2
), the ActivityTestRule
dependency is found in
androidTestImplementation 'com.android.support.test:rules:1.0.2'
It would probably be a good idea to check the official documentation to make sure that the rest of the dependencies are set up correctly as well, but here's what I'd recommend to get started with Espresso.
In the dependencies
section of app/build.gradle
, add this:
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
In the defaultConfig
section of app/build.gradle
, add this:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
If you encounter other similar problems, the documentation includes a long list of other gradle dependencies that might have what you need, but what I've listed above should be enough to get you started.
Upvotes: 5