My app consists of one
Espresso can test
Fragments only if they are displayed. And that requires them to be displayed by an
With your current setup you'll have to use Espresso to
click() your way (like a user would) to the
Fragment you actually want to test.
In one of my projects I have a
ViewPager that displays
Fragments. For those
Fragments I use a custom
FragmentTestRule to test them in isolation. I can start each
Fragment directly and use Espresso to test it. See this answer.
You could also:
Activitiesare easier to test. You can test each
Activityon its own. In most cases
Fragmentsoffer no advantage over
Fragmentsjust make the implementation and testing more difficult.
FragmentActivityto directly show a certain
Fragmentwhen it is created. E.g. by supplying a special intent extra to your
FragmentActivity. But this would add testing code to your app, which is generally not a good solution.