Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#503·testing-samples

Not compiling test class with a fragment that not inherits directly but indirectly from Fragment class

Author: albertB4workCreated Jan 16, 2024Updated Jan 16, 2024

I'm working with this code:

@RunWith(AndroidJUnit4ClassRunner::class)
class FiltersFragmentTest {

    @Test
    fun fragmentIsVisible() {
        val scenario = launchFragmentInContainer<FiltersFragment>()
        scenario.recreate()
        Espresso
            .onView(ViewMatchers.withId(R.id.jvQuery))
            .check(matches(isDisplayed()))
    }
}

The FiltersFragment class inherits from a class custom, that inherits from another custom base fragment class that inherits from Fragment (androidx.fragment.app.Fragment). But when trying to execute the test an error is shown in compile time

Cannot access class 'androidx.fragment.app.FragmentFactory'. Check your module classpath for missing or conflicting dependencies Type argument is not within its bounds: should be subtype of 'Fragment'

I see in my project dependencies two versions of fragment library: 1.3.6 for appCompat library use and direct dependency 1.6.2 Both have FragmentFactory class inside

Source: android/testing-samples

View original on GitHubView discussion on GitHub