How To Mock Bundle Method In Android Unit-test?
I have one controller class that handle Fragment creation. Let's say like below: public class FragmentController { public static Fragment newInstance(String title, int total)
Solution 1:
One way could be to use a powerful mocking framework like PowerMock, which can even intercept the construction of new objects.
This should work for you but mocking "simple" classes like Bundle means some effort - you could also use the real implementation by using the UnMock plugin.
Solution 2:
Use the Unmock plugin to un-mock the Bundle class. You'll need to un-mock with Android 4.4 (unmock 'org.robolectric:android-all:4.4_r1-robolectric-1'
) since later versions of Android reference non-standard Java methods.
You'll also need to keep ArrayMap and MapCollections.
Post a Comment for "How To Mock Bundle Method In Android Unit-test?"