# FragmentScenario

Artifact: [androidx.fragment:fragment-testing](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/testing/FragmentScenario.kt+class:androidx.fragment.app.testing.FragmentScenario) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

*** ** * ** ***


```
class FragmentScenario<F : Fragment> : Closeable
```

<br />

*** ** * ** ***

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 `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment`. If you are using a deprecated fragment class such as `android.support.v4.app.Fragment` or `https://developer.android.com/reference/android/app/Fragment.html`, please update your code to `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment`.

If your testing Fragment has a dependency to specific theme such as `Theme.AppCompat`, use the theme ID parameter in `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#launch(java.lang.Class,android.os.Bundle,androidx.fragment.app.FragmentFactory)` method.

| Parameters |
|---|---|
| `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment>` | The Fragment class being tested |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/test/core/app/ActivityScenario` | a scenario API for Activity |

## Summary

| ### Nested types |
|---|
| `fun interface https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.FragmentAction<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment>` FragmentAction interface should be implemented by any class whose instances are intended to be executed by the main thread. |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#launch(java.lang.Class,android.os.Bundle,androidx.fragment.app.FragmentFactory)( fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>, fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?, factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory? )` Launches a Fragment with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach the resumed state. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#launch(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.fragment.app.FragmentFactory)( fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>, fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?, themeResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory? )` Launches a Fragment with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` themed by `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launch(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.fragment.app.FragmentFactory)`, using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach the resumed state. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#launch(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)( fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>, fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?, themeResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, initialState: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State, factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory? )` Launches a Fragment with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` themed by `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launch(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)`, using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launch(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)`. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#launchInContainer(java.lang.Class,android.os.Bundle,androidx.fragment.app.FragmentFactory)( fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>, fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?, factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory? )` Launches a Fragment in the Activity's root view container `android.R.id.content`, with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach the resumed state. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#launchInContainer(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.fragment.app.FragmentFactory)( fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>, fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?, themeResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory? )` Launches a Fragment in the Activity's root view container `android.R.id.content`, with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` themed by `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launchInContainer(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.fragment.app.FragmentFactory)`, using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach the resumed state. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#launchInContainer(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)( fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>, fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?, themeResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, initialState: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State, factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory? )` Launches a Fragment in the Activity's root view container `android.R.id.content`, with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` themed by `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launchInContainer(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)`, using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launchInContainer(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)`. |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#close()()` Finishes the managed fragments and cleans up device's state. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#moveToState(androidx.lifecycle.Lifecycle.State)(newState: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State)` Moves Fragment state to a new state. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#onFragment(androidx.fragment.app.testing.FragmentScenario.FragmentAction)(action: https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.FragmentAction<F>)` Runs a given `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#onFragment(androidx.fragment.app.testing.FragmentScenario.FragmentAction)` on the current Activity's main thread. |
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#recreate()()` Recreates the host Activity. |

| ### Extension functions |
|---|---|
| `inline T` | `<F : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment, T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario<F>.https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#(androidx.fragment.app.testing.FragmentScenario).withFragment(kotlin.Function1)( crossinline block: F.() -> T )` Run `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/package-summary#(androidx.fragment.app.testing.FragmentScenario).withFragment(kotlin.Function1)` using `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#onFragment(androidx.fragment.app.testing.FragmentScenario.FragmentAction)`, returning the result of the `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/package-summary#(androidx.fragment.app.testing.FragmentScenario).withFragment(kotlin.Function1)`. |

## Public companion functions

### launch

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
fun <F : Fragment> launch(
    fragmentClass: Class<F>,
    fragmentArgs: Bundle?,
    factory: FragmentFactory?
): FragmentScenario<F>
```

Launches a Fragment with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach the resumed state.

This method cannot be called from the main thread.

| Parameters |
|---|---|
| `fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>` | a fragment class to instantiate |
| `fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?` | a bundle to passed into fragment |
| `factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory?` | a fragment factory to use or null to use default factory |

### launch

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
fun <F : Fragment> launch(
    fragmentClass: Class<F>,
    fragmentArgs: Bundle?,
    themeResId: @StyleRes Int,
    factory: FragmentFactory?
): FragmentScenario<F>
```

Launches a Fragment with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` themed by `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launch(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.fragment.app.FragmentFactory)`, using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach the resumed state.

This method cannot be called from the main thread.

| Parameters |
|---|---|
| `fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>` | a fragment class to instantiate |
| `fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?` | a bundle to passed into fragment |
| `themeResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | a style resource id to be set to the host activity's theme |
| `factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory?` | a fragment factory to use or null to use default factory |

### launch

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
fun <F : Fragment> launch(
    fragmentClass: Class<F>,
    fragmentArgs: Bundle? = null,
    themeResId: @StyleRes Int = R.style.FragmentScenarioEmptyFragmentActivityTheme,
    initialState: Lifecycle.State = Lifecycle.State.RESUMED,
    factory: FragmentFactory? = null
): FragmentScenario<F>
```

Launches a Fragment with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` themed by `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launch(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)`, using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launch(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)`.

This method cannot be called from the main thread.

| Parameters |
|---|---|
| `fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>` | a fragment class to instantiate |
| `fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html? = null` | a bundle to passed into fragment |
| `themeResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = R.style.FragmentScenarioEmptyFragmentActivityTheme` | a style resource id to be set to the host activity's theme |
| `initialState: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State = Lifecycle.State.RESUMED` | The initial `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State`. Passing in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` will result in an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`. |
| `factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory? = null` | a fragment factory to use or null to use default factory |

### launchInContainer

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
fun <F : Fragment> launchInContainer(
    fragmentClass: Class<F>,
    fragmentArgs: Bundle?,
    factory: FragmentFactory?
): FragmentScenario<F>
```

Launches a Fragment in the Activity's root view container `android.R.id.content`, with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach the resumed state.

This method cannot be called from the main thread.

| Parameters |
|---|---|
| `fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>` | a fragment class to instantiate |
| `fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?` | a bundle to passed into fragment |
| `factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory?` | a fragment factory to use or null to use default factory |

### launchInContainer

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
fun <F : Fragment> launchInContainer(
    fragmentClass: Class<F>,
    fragmentArgs: Bundle?,
    themeResId: @StyleRes Int,
    factory: FragmentFactory?
): FragmentScenario<F>
```

Launches a Fragment in the Activity's root view container `android.R.id.content`, with given arguments hosted by an empty `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` themed by `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launchInContainer(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.fragment.app.FragmentFactory)`, using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach the resumed state.

This method cannot be called from the main thread.

| Parameters |
|---|---|
| `fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>` | a fragment class to instantiate |
| `fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html?` | a bundle to passed into fragment |
| `themeResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | a style resource id to be set to the host activity's theme |
| `factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory?` | a fragment factory to use or null to use default factory |

### launchInContainer

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
fun <F : Fragment> launchInContainer(
    fragmentClass: Class<F>,
    fragmentArgs: Bundle? = null,
    themeResId: @StyleRes Int = R.style.FragmentScenarioEmptyFragmentActivityTheme,
    initialState: Lifecycle.State = Lifecycle.State.RESUMED,
    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 `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentActivity` themed by `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launchInContainer(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)`, using the given `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory` and waits for it to reach `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario.Companion#launchInContainer(java.lang.Class,android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)`.

This method cannot be called from the main thread.

| Parameters |
|---|---|
| `fragmentClass: https://developer.android.com/reference/java/lang/Class.html<F>` | a fragment class to instantiate |
| `fragmentArgs: https://developer.android.com/reference/android/os/Bundle.html? = null` | a bundle to passed into fragment |
| `themeResId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = R.style.FragmentScenarioEmptyFragmentActivityTheme` | a style resource id to be set to the host activity's theme |
| `initialState: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State = Lifecycle.State.RESUMED` | The initial `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State`. Passing in `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` will result in an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`. |
| `factory: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentFactory? = null` | a fragment factory to use or null to use default factory |

## Public functions

### close

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0)

```
open fun close(): Unit
```

Finishes the managed fragments and cleans up device's state. This method blocks execution until the host activity becomes `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED`.

### moveToState

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
fun moveToState(newState: Lifecycle.State): FragmentScenario<F>
```

Moves Fragment state to a new state.

If a new state and current state are the same, this method does nothing. It accepts all `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State`s. `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED` is a terminal state. You cannot move to any other state after the Fragment reaches that state.

This method cannot be called from the main thread.

### onFragment

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
fun onFragment(action: FragmentScenario.FragmentAction<F>): FragmentScenario<F>
```

Runs a given `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#onFragment(androidx.fragment.app.testing.FragmentScenario.FragmentAction)` on the current Activity's main thread.

Note that you should never keep Fragment reference passed into your `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#onFragment(androidx.fragment.app.testing.FragmentScenario.FragmentAction)` because it can be recreated at anytime during state transitions.

Throwing an exception from `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#onFragment(androidx.fragment.app.testing.FragmentScenario.FragmentAction)` makes the host Activity crash. You can inspect the exception in logcat outputs.

This method cannot be called from the main thread.

### recreate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
fun recreate(): FragmentScenario<F>
```

Recreates the host Activity.

After this method call, it is ensured that the Fragment state goes back to the same state as its previous state.

This method cannot be called from the main thread.

## Extension functions

### FragmentScenario.withFragment

Artifact: [androidx.fragment:fragment-testing](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/testing/FragmentScenario.kt+function:withFragment)

```
inline fun <F : Fragment, T : Any> FragmentScenario<F>.withFragment(
    crossinline block: F.() -> T
): T
```

Run `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/package-summary#(androidx.fragment.app.testing.FragmentScenario).withFragment(kotlin.Function1)` using `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/FragmentScenario#onFragment(androidx.fragment.app.testing.FragmentScenario.FragmentAction)`, returning the result of the `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/package-summary#(androidx.fragment.app.testing.FragmentScenario).withFragment(kotlin.Function1)`.

If any exceptions are raised while running `https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/package-summary#(androidx.fragment.app.testing.FragmentScenario).withFragment(kotlin.Function1)`, they are rethrown.