FragmentScenario
class FragmentScenario<F : Fragment>
kotlin.Any | |
↳ | androidx.fragment.app.testing.FragmentScenario |
FragmentScenario provides API to start and drive a Fragment's lifecycle state for testing. It works with arbitrary fragments and works consistently across different versions of the Android framework.
FragmentScenario only supports androidx.fragment.app.Fragment. If you are using
a deprecated fragment class such as android.support.v4.app.Fragment
or
android.app.Fragment, please update your code to
androidx.fragment.app.Fragment.
If your testing Fragment has a dependency to specific theme such as Theme.AppCompat
,
use the theme ID parameter in launch method.
Summary
Nested classes | |
---|---|
abstract |
Public methods | |
---|---|
Unit |
FragmentAction interface should be implemented by any class whose instances are intended to be executed by the main thread. |
FragmentScenario<F> |
moveToState(newState: Lifecycle.State) Moves Fragment state to a new state. |
FragmentScenario<F> |
onFragment(action: FragmentScenario.FragmentAction<F>) Runs a given action on the current Activity's main thread. |
FragmentScenario<F> |
recreate() Recreates the host Activity. |
Companion functions | |
---|---|
FragmentScenario<F> |
launch(fragmentClass: Class<F>, fragmentArgs: Bundle?, factory: FragmentFactory?) Launches a Fragment with given arguments hosted by an empty FragmentActivity using the given FragmentFactory and waits for it to reach the resumed state. |
FragmentScenario<F> |
launch(fragmentClass: Class<F>, fragmentArgs: Bundle?, @StyleRes themeResId: Int, factory: FragmentFactory?) Launches a Fragment with given arguments hosted by an empty FragmentActivity themed by themeResId, using the given FragmentFactory and waits for it to reach the resumed state. |
FragmentScenario<F> |
launch(fragmentClass: Class<F>, fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, initialState: Lifecycle.State = Lifecycle.State.RESUMED, factory: FragmentFactory? = null) Launches a Fragment with given arguments hosted by an empty FragmentActivity themed by themeResId, using the given FragmentFactory and waits for it to reach initialState. |
FragmentScenario<F> |
launchInContainer(fragmentClass: Class<F>, fragmentArgs: Bundle?, factory: FragmentFactory?) Launches a Fragment in the Activity's root view container |
FragmentScenario<F> |
launchInContainer(fragmentClass: Class<F>, fragmentArgs: Bundle?, @StyleRes themeResId: Int, factory: FragmentFactory?) Launches a Fragment in the Activity's root view container |
FragmentScenario<F> |
launchInContainer(fragmentClass: Class<F>, fragmentArgs: Bundle? = null, @StyleRes |