public final class FragmentScenario<F extends Fragment>

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 If you are using a deprecated fragment class such as or, please update your code to

If your testing Fragment has a dependency to specific theme such as Theme.AppCompat, use the theme ID parameter in launch method.

<F extends Fragment>

The Fragment class being tested

See also

a scenario API for Activity


Nested types


FragmentAction interface should be implemented by any class whose instances are intended to be executed by the main thread.

Public methods


Finishes the managed fragments and cleans up device's state.

final @NonNull FragmentScenario<@NonNull F>

Moves Fragment state to a new state.

final @NonNull FragmentScenario<@NonNull F>

Runs a given action on the current Activity's main thread.

final @NonNull FragmentScenario<@NonNull F>

Recreates the host Activity.

Extension functions

final @NonNull T
<F extends Fragment, T extends Object> FragmentScenarioKt.withFragment(
    FragmentScenario<F> receiver,
    @ExtensionFunctionType Function1<F, T> block

Run block using FragmentScenario.onFragment, returning the result of the block.

Public methods