This blog post describes my experiences migrating a unit test from Robolectric ‘old’ API to the new AndroidX FragmentScenario API. I wanted to do that as part of experimenting this new API, which brings some advantages over the old method (see http://robolectric.org/androidx_test/).

My previous approach usually involved setting up the parent activity and then simulating all the steps until the Fragment under test was visible in that activity — which was not trivial, because it involved setting up the test dependencies for both the Fragment and parent activity.

As an example: