Roblectric's FragmentController
allowed us to drive the lifecycle of the Fragment
to a desired state. It seems that FragmentScenario
always takes the Fragment
under test to its resumed state. One would assume that calling moveToState(CREATED)
would take the Fragment
back to through its onCreate()
, but in reality, as per the docs, moveToState()
simulates an external app interacting with the Fragment
under test. This means that moveToState(CREATED)
moves the Fragment
under test through onPause()
and onStop()
as it would happen when a new Activity
is launched.
To drive the fragment to a different lifecycle state, call moveToState(). This methods supports the following states as arguments: CREATED, STARTED, RESUMED, and DESTROYED. This action simulates a situation where the activity containing your fragment changes its state because it's interrupted by another app or a system action.
Is it possible to somehow direct FragmentScenario
to drive the Fragment
to a desired state instead of always going through onResume()
? How do we test that something happened inside onCreate()
and not inside onResume()
using FragmentScenario
? Am I missing something here?