Únete a ⁠ #Android11: The Beta Launch Show el 3 de junio.

androidx.fragment.app.testing

Classes

FragmentScenario

FragmentScenario provides API to start and drive a Fragment's lifecycle state for testing.

Top-level functions summary

FragmentScenario<F!>
launchFragment(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, factory: FragmentFactory? = null)

Launches a Fragment with given arguments hosted by an empty FragmentActivity using given FragmentFactory and waits for it to reach a resumed state.

FragmentScenario<F!>
launchFragment(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, crossinline instantiate: () -> F)

Launches a Fragment with given arguments hosted by an empty FragmentActivity using instantiate to create the Fragment and waits for it to reach a resumed state.

FragmentScenario<F!>
launchFragmentInContainer(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, factory: FragmentFactory? = null)

Launches a Fragment in the Activity's root view container android.R.id.content, with given arguments hosted by an empty FragmentActivity and waits for it to reach a resumed state.

FragmentScenario<F!>
launchFragmentInContainer(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, crossinline instantiate: () -> F)

Launches a Fragment in the Activity's root view container android.R.id.content, with given arguments hosted by an empty FragmentActivity using instantiate to create the Fragment and waits for it to reach a resumed state.

Top-level functions

launchFragment

inline fun <reified F : Fragment> launchFragment(
    fragmentArgs: Bundle? = null,
    @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme,
    factory: FragmentFactory? = null
): FragmentScenario<F!>

Launches a Fragment with given arguments hosted by an empty FragmentActivity using given FragmentFactory and waits for it to reach a resumed state.

This method cannot be called from the main thread.

Parameters
fragmentArgs: Bundle? = null a bundle to passed into fragment
themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme a style resource id to be set to the host activity's theme
factory: FragmentFactory? = null a fragment factory to use or null to use default factory

launchFragment

inline fun <reified F : Fragment> launchFragment(
    fragmentArgs: Bundle? = null,
    @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme,
    crossinline instantiate: () -> F
): FragmentScenario<F!>

Launches a Fragment with given arguments hosted by an empty FragmentActivity using instantiate to create the Fragment and waits for it to reach a resumed state.

This method cannot be called from the main thread.

Parameters
fragmentArgs: Bundle? = null a bundle to passed into fragment
themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme a style resource id to be set to the host activity's theme
instantiate: () -> F method which will be used to instantiate the Fragment.

launchFragmentInContainer

inline fun <reified F : Fragment> launchFragmentInContainer(
    fragmentArgs: Bundle? = null,
    @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme,
    factory: FragmentFactory? = null
): FragmentScenario<F!>

Launches a Fragment in the Activity's root view container android.R.id.content, with given arguments hosted by an empty FragmentActivity and waits for it to reach a resumed state.

This method cannot be called from the main thread.

Parameters
fragmentArgs: Bundle? = null a bundle to passed into fragment
themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme a style resource id to be set to the host activity's theme
factory: FragmentFactory? = null a fragment factory to use or null to use default factory

launchFragmentInContainer

inline fun <reified F : Fragment> launchFragmentInContainer(
    fragmentArgs: Bundle? = null,
    @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme,
    crossinline instantiate: () -> F
): FragmentScenario<F!>

Launches a Fragment in the Activity's root view container android.R.id.content, with given arguments hosted by an empty FragmentActivity using instantiate to create the Fragment and waits for it to reach a resumed state.

This method cannot be called from the main thread.

Parameters
fragmentArgs: Bundle? = null a bundle to passed into fragment
themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme a style resource id to be set to the host activity's theme
instantiate: () -> F method which will be used to instantiate the Fragment. This is a simplification of the FragmentFactory interface for cases where only a single class needs a custom constructor called.