Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed butterknife from contributions list fragment #5396

Conversation

psh
Copy link
Collaborator

@psh psh commented Nov 28, 2023

This PR removes Butterknife from the ContributionsListFragment.

A large barrier to removing Butterknife from other places in the code is the plethora of mock UI elements that rely on Butterknife bound member variables. The PR introduces Google's FragmentScenario - designed for unit testing Fragments - along with a slight bump to some library versions.

FragmentScenario gives you complete control of the Fragment lifecycle and coupled with Robolectric allows you to safely run through the onCreateView() method to create real components removing the need for all the mock objects. As you can see from the PR, this greatly simplifies the test!

The pattern for other tests will be fairly similar to -

private lateinit var scenario: FragmentScenario<ContributionsListFragment>
private lateinit var fragment: ContributionsListFragment

and in the setup method

scenario = launchFragmentInContainer(
    initialState = Lifecycle.State.RESUMED,
    themeResId = R.style.LightAppTheme
) {
    ContributionsListFragment().apply {
        // ... setup mock objects on the target class, if needed
    }.also {
        fragment = it
    }
}

if you dont want to keep a fragment reference, then use FragmentScenario -

scenario.onFragment {
    // "it" is the fragment we're testing
    it.adapter = adapter
}

@nicolas-raoul
Copy link
Member

Apparently for this branch unit tests fail with this:

Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.8.20 (org.jetbrains.kotlin:kotlin-stdlib:1.8.20) and jetified-kotlin-stdlib-jdk7-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20)

Any idea what might be the issue?

@psh
Copy link
Collaborator Author

psh commented Dec 13, 2023

Been a busy couple of weeks - I will look into this. No idea about why yet though.

@psh
Copy link
Collaborator Author

psh commented Dec 22, 2023

StackOverflow had an answer - looks like things build now.

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, everything working fine.
Thanks! :-)

@nicolas-raoul nicolas-raoul merged commit 3d525d4 into commons-app:main Dec 23, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants