Issue
I am learning TDD for Android using this demo:
https://github.com/NileshJarad/TDD_Demo
I can run all the unit tests and the Mockito tests, but the "activityTests" fail with these errors:
error: package android.support.test.rule does not exist
error: package android.support.test.espresso does not exist
error: package android.support.test.espresso.action does not exist
error: package android.support.test.espresso.action does not exist
error: package android.support.test.espresso.action does not exist
error: package android.support.test.espresso.assertion does not exist
error: package android.support.test.espresso.matcher does not exist
error: package android.support.test.espresso.matcher does not exist
error: package android.support.test.espresso.matcher does not exist
error: cannot find symbol class ActivityTestRule
error: cannot find symbol method isDisplayed()
...
The versions are Android 9.0 API 28.
I tried the suggestions at https://www.google.com/search?q=Android+ActivityTest+gives+%27package+android.support.test.rule+does+not+exist%27 but they all refer to app/build.gradle lines that we already have:
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
...
dependencies {
...
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestImplementation 'com.android.support.test:testing-support-lib:0.1'
}
Solution
I think that you just need to change the "rules" dependency to an AndroidX version:
androidTestImplementation 'androidx.test:rules:1.2.0'
After syncing the project, you'll need to change your tests to use androidx.test.* instead of android.support.test.* (which you can do by deleting the greyed-out import statements and then just accepting all of the new imports that Android Studio suggests).
At this point, your tests should run!
One more thing: You can now delete the annotation at the top of your test class in which "AndroidJUnit4" is marked as deprecated (ie crossed out):
@RunWith(AndroidJUnit4.class)
According to the documentation, @RunWith is now only required when using a mix of JUnit3 and JUnit4 (which your test does not).
Answered By - Rapunzel Van Winkle
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.