HiltFragmentScenario

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.

Parameters

F

The Fragment class being tested

See also

a scenario API for Activity

Types

Link copied to clipboard
object Companion
Link copied to clipboard
fun interface FragmentAction<F : Fragment>

FragmentAction interface should be implemented by any class whose instances are intended to be executed by the main thread. A Fragment that is instrumented by the FragmentScenario is passed to FragmentAction.perform method.

Functions

Link copied to clipboard
open override fun close()

Finishes the managed fragments and cleans up device's state. This method blocks execution until the host activity becomes Lifecycle.State.DESTROYED.

Link copied to clipboard

Moves Fragment state to a new state.

Link copied to clipboard

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

Link copied to clipboard

Recreates the host Activity.

Link copied to clipboard
inline fun <F : Fragment, T : Any> HiltFragmentScenario<F>.withFragment(crossinline block: F.() -> T): T

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