android / android/testing-samples

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

Open
#503 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
9.3k
Forks
3.6k
PR merge metrics
No merged PRs in 30d

Description

I'm working with this code:

```
@RunWith(AndroidJUnit4ClassRunner::class)
class FiltersFragmentTest {

@Test
fun fragmentIsVisible() {
val scenario = launchFragmentInContainer()
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

Contributor guide

Open the contributing guide

Research direction

Start with the FiltersFragmentTest entry point and the module dependency declarations; reproduce compilation of launchFragmentInContainer and inspect the resolved androidx.fragment versions. Confirm whether the test compiles when Fragment is inherited indirectly, and record the dependency/version state that determines the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.