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

org.robolectric:shadows-supportv4 doesn't support Jetpack(androidx) #3985

Closed
XinyueZ opened this issue Aug 30, 2018 · 25 comments
Closed

org.robolectric:shadows-supportv4 doesn't support Jetpack(androidx) #3985

XinyueZ opened this issue Aug 30, 2018 · 25 comments
Milestone

Comments

@XinyueZ
Copy link

XinyueZ commented Aug 30, 2018

Main repo: org.robolectric:robolectric:4.0-alpha-4-SNAPSHOT works with androidx
org.robolectric:shadows-supportv4 doesn't work, ie:

class TestSupportFragment extends androidx.fragment.app.Fragment

doesn't work -----> SupportFragmentController.of(new TestSupportFragment())

any snapshot for shadows-supportv4 ?

issue

@seadowg
Copy link
Collaborator

seadowg commented Sep 1, 2018

Seeing this as well. Using the new androidx Fragment class doesn't appear to work. Android Studio warns you that your Fragment is not a subtype of android.support.v4.app.Fragment and there is a no such method error when running a test:

java.lang.NoSuchMethodError: org.robolectric.shadows.support.v4.SupportFragmentController.of(Landroidx/fragment/app/Fragment;)Lorg/robolectric/shadows/support/v4/SupportFragmentController;

@seadowg
Copy link
Collaborator

seadowg commented Sep 3, 2018

Interestingly if I run tests through Gradle directly (and not through Android Studio) they are fine. Could this be a problem with Jetifier?

@XinyueZ
Copy link
Author

XinyueZ commented Sep 3, 2018

If you don't edit the whole project which means all package names of android.support.fragment to the androidx.app.fragment.
Try to edit the whole project with the androidx namespace and dependencies of fragment, you will see the problem @seadowg

@sdetilly
Copy link

Any news on this? Some of my tests are failing because of the "NoSuchMethodError" problem

@XinyueZ
Copy link
Author

XinyueZ commented Sep 28, 2018

@sdetilly Actually I have done it by myself, here is one example:
https://github.com/XinyueZ/easypermissions/blob/feature/androidx/easypermissions/src/test/java/pub/devrel/easypermissions/SupportFragmentController.java

@userdimi
Copy link

Have the same issue. I can't create a andoidx.fragment.app Fragment with Robolectric

@jongerrish
Copy link
Contributor

jongerrish commented Oct 22, 2018 via email

@chriscoomber
Copy link

@jongerrish any update on this? Or known workarounds? We've not been able to run any of our Fragment tests in Android studio because of this (but for some reason, as mentioned above, they still work on the command line).

@jongerrish
Copy link
Contributor

We have a new API for Fragments which should launch Monday and is compatible both for Instrumentation tests and local tests in Robolectric.

@Sai-Deepthi
Copy link

@jongerrish any particular release date for it?

@jongerrish jongerrish added this to the 4.0.2 milestone Nov 4, 2018
@jongerrish
Copy link
Contributor

@Sai-Deepthi It was released this week.

More details here:- https://developer.android.com/training/basics/fragments/testing

@xian xian modified the milestones: 4.0.2, 4.0.3 Nov 9, 2018
@NickButcher1
Copy link

The new FragmentScenario library won't help with org.robolectric.shadows.support.v4.ShadowLocalBroadcastManager will it? Won't I still need the shadows-supportv4 dependency if I want to use ShadowLocalBroadcastManager?

@jongerrish
Copy link
Contributor

jongerrish commented Nov 13, 2018 via email

@NickButcher1
Copy link

I'm happy to try and remove my need for ShadowLocalBroadcastManager by following the advice in #2849. Thanks!

@jongerrish
Copy link
Contributor

jongerrish commented Nov 13, 2018 via email

@NickButcher1
Copy link

No problems. I fixed my tests, as suggested, to register a LocalBroadcastReceiver which checks that the Intents that it receives match what the test cases are expecting.

@gefilte
Copy link

gefilte commented Nov 14, 2018

Definitely would have been a smoother transition to AndroidX if this worked... right now I've had to mark some tests as @ignore until I can rewrite them. They all use startFragment which oddly enough compiles despite the linter warning, but fails to run since the method signatures are looking for support library Fragment and Activity classes, but I've got AndroidX variants.

@luongvo
Copy link

luongvo commented Nov 24, 2018

@XinyueZ @seadowg @sdetilly @userdimi I met this issue too, so I just created this clones: https://github.com/nimbl3/robolectric.shadows-supportv4, it helps support current tests using robolectric:shadows-supportv4 works without any changes in test codes. Maybe it could help you while waiting for official support from robolectric team 🚀

Example here: https://github.com/nimbl3/robolectric.shadows-supportv4/blob/master/app/src/test/java/co/nimblehq/robolectric/shadows/supportv4/TestFragmentTest.kt

@KevinLeigh
Copy link

Hey @XinyueZ @seadowg @sdetilly @userdimi,

You can use FragmentScenario from package -> androidx.fragment:fragment-testing

See Official doc: https://developer.android.com/training/basics/fragments/testing

@sdetilly
Copy link

@luongvo Thank you very much for the library! it helps alot! @KevinLeigh I think i will wait until androidx.fragment:fragment-testing is out of alpha before integrating in my production app. I am worried that it can introduce bugs

@msawan-resilient
Copy link

Hi all,

Any update on this issue?

miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Dec 26, 2019
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Dec 26, 2019
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Jan 15, 2020
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Feb 19, 2020
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Feb 19, 2020
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Feb 19, 2020
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Feb 19, 2020
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Feb 19, 2020
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Mar 20, 2020
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Mar 20, 2020
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
miankhalid added a commit to openedx-unsupported/edx-app-android that referenced this issue Mar 20, 2020
Issue: "org.robolectric:shadows-supportv4:{latest_version}" library
This library from Robolectric doesn't support AndroidX and internally
uses support-v4 package.

Reference Issue: robolectric/robolectric#3985

Temporary Resolution:
As a workaround I've switched to using a clone of this library which
supports AndroidX. Inspiration taken from here:
robolectric/robolectric#3985 (comment)

Actual Resolution:
If this passes our tests, a future task should be created to start using
FragmentScenario from package -> androidx.fragment:fragment-testing

Official Doc: https://developer.android.com/training/basics/fragments/testing
@utzcoz
Copy link
Member

utzcoz commented Apr 8, 2023

The Robolectric has removed shadows for v4 from 4.9. So I will close this issue. Feel free to reopen this issue if you have similar issues when running the latest Robolectric with AndroidX.

@utzcoz utzcoz closed this as completed Apr 8, 2023
@seadowg
Copy link
Collaborator

seadowg commented Apr 10, 2023

@utzcoz is there any plan to provide Shadows for other (that Fragment) AndroidX component like AlertDialog? I'd be interested to know if the thinking is that people should create their own custom ones, or if there's a hope that Shadows can be avoided as the AndroidX APIs play nicer with tests? The latter seems to be a direction we're heading in.

@utzcoz
Copy link
Member

utzcoz commented Apr 10, 2023

is there any plan to provide Shadows for other (that Fragment) AndroidX component like AlertDialog

I think not, at least from my part. The Robolectric focus on the main components of AOSP's frameworks, and AndroidX components are separate. If these components rely on AOSP's components, I think we can improve the shadow of the AOSP's one to fix issues for these AndroidX components. If not, users/developers can maintain the custom shadow for these components if needed. @hoisie What do you think?

@brettchabot
Copy link
Contributor

androidx libraries should not require shadows. If you find an androidx API that isn't testable I'd recommend filing an issue against androidx.

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

No branches or pull requests