Android fragment in isolation
Solution 1:
The error was related to the way I did import the dependencies on Gradle.
Before:
androidTestImplementation("androidx.fragment:fragment-testing:1.1.0-beta01")
implementation("androidx.fragment:fragment-ktx:1.1.0-beta01")
androidTestImplementation("androidx.test:core:1.2.0")
androidTestImplementation("androidx.test:rules:1.2.0")
androidTestImplementation("androidx.test:runner:1.2.0")
After:
debugImplementation("androidx.fragment:fragment-testing:1.1.0-beta01")
debugImplementation("androidx.fragment:fragment-ktx:1.1.0-beta01")
debugImplementation("androidx.test:core:1.2.0")
debugImplementation("androidx.test:rules:1.2.0")
debugImplementation("androidx.test:runner:1.2.0")
Changed from androidTestImplementation
to debugImplementation
and it solved the issue. Compiling and running, and green test as result.
Solution 2:
Try to configure this way
debugImplementation('androidx.fragment:fragment-testing:1.1.0') {
// exclude androidx.test:core while fragment_testing depends on 1.1.0
exclude group: 'androidx.test', module: 'core'
}
Solution 3:
it works for me
def fragmentx_version = "1.1.0"
implementation "androidx.fragment:fragment:$fragmentx_version"
debugImplementation ("androidx.fragment:fragment-testing:$fragmentx_version"){
exclude group: 'androidx.test', module: 'core'
}
debugImplementation 'androidx.test:core-ktx:1.2.0'
@Test
fun verifyMap() {
FragmentScenario.launchInContainer(HomeFragment::class.java)
onView(withId(R.id.map)).check(matches(isDisplayed()))
}