# AndroidComposeUiTest

Artifact: [androidx.compose.ui:ui-test](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/ComposeUiTest.android.kt+class:androidx.compose.ui.test.AndroidComposeUiTest) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0) Common/AllAndroid/JVM
- android

  ```
  sealed interface AndroidComposeUiTest<A : ComponentActivity> : ComposeUiTest, IdlingResourceOwner
  ```

*** ** * ** ***

Variant of `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest` for when you want to have access the current `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/AndroidComposeUiTest#activity()` of type `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/AndroidComposeUiTest`. The activity might not always be available, for example if the test navigates to another activity. In such cases, `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/AndroidComposeUiTest#activity()` will return `null`.

An instance of `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/AndroidComposeUiTest` can be obtained by calling `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#runAndroidComposeUiTest(kotlin.coroutines.CoroutineContext,kotlin.coroutines.CoroutineContext,kotlin.time.Duration,kotlin.coroutines.SuspendFunction1)`, the argument to which will have it as the receiver scope.

Note that any Compose content can be found and tested, regardless if it is hosted by `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/AndroidComposeUiTest#activity()` or not. What is important, is that the content is set *during* the lambda passed to `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#runAndroidComposeUiTest(kotlin.coroutines.CoroutineContext,kotlin.coroutines.CoroutineContext,kotlin.time.Duration,kotlin.coroutines.SuspendFunction1)` (not before, and not after), and that the activity that is actually hosting the Compose content is in resumed state.

| Parameters |
|---|---|
| `<A : https://developer.android.com/reference/kotlin/androidx/activity/ComponentActivity>` | The Activity type to be interacted with, which typically (but not necessarily) is the activity that was launched and hosts the Compose content |

## Summary

| ### Public properties |
|---|---|---|
| `A?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/AndroidComposeUiTest#activity()` Returns the current activity of type `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/AndroidComposeUiTest` used in this `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest`. | android |

### Inherited functions

From [androidx.compose.ui.test.ComposeUiTest](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest) `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#awaitIdle()()`

Suspends until the UI is idle.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#hasPendingWork()()`

Returns whether the Compose UI has any pending work.
android `T` `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#runOnIdle(kotlin.Function0)(action: () -> T)`

Executes the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#runOnIdle(kotlin.Function0)` in the same way as `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#runOnUiThread(kotlin.Function0)` but `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#waitForIdle()` until the app is idle before executing the action.
android `T` `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#runOnUiThread(kotlin.Function0)(action: () -> T)`

Runs the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#runOnUiThread(kotlin.Function0)` on the UI thread.
android `T` `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#runWithoutImplicitWait(kotlin.Function0)(block: () -> T)`

Executes the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#runWithoutImplicitWait(kotlin.Function0)` with implicit synchronization suppressed.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#setContent(kotlin.Function0)(composable: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`

Sets the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#setContent(kotlin.Function0)` as the content to be tested.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#waitForIdle()()`

Waits for the UI to become idle.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#waitUntil(kotlin.String,kotlin.Long,kotlin.Function0)(
conditionDescription: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?,
timeoutMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html,
condition: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html
)`

Blocks until the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#waitUntil(kotlin.String,kotlin.Long,kotlin.Function0)` is satisfied.
android From [androidx.compose.ui.test.IdlingResourceOwner](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IdlingResourceOwner) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IdlingResourceOwner#registerIdlingResource(androidx.compose.ui.test.IdlingResource)(idlingResource: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IdlingResource)`

Registers an `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IdlingResource` in this test.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IdlingResourceOwner#unregisterIdlingResource(androidx.compose.ui.test.IdlingResource)(idlingResource: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IdlingResource)`

Unregisters an `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IdlingResource` from this test.
android From [androidx.compose.ui.test.SemanticsNodeInteractionsProvider](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsNodeInteractionsProvider) `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsNodeInteractionCollection` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsNodeInteractionsProvider#onAllNodes(androidx.compose.ui.test.SemanticsMatcher,kotlin.Boolean)(matcher: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsMatcher, useUnmergedTree: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`

Finds all semantics nodes that match the given condition.
android `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsNodeInteraction` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsNodeInteractionsProvider#onNode(androidx.compose.ui.test.SemanticsMatcher,kotlin.Boolean)(matcher: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsMatcher, useUnmergedTree: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`

Finds a semantics node that matches the given condition.
android

### Inherited properties

From [androidx.compose.ui.test.ComposeUiTest](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest) `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#density()`

Current device screen's density.
android `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/MainTestClock` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest#mainClock()`

Clock that drives frames and recompositions in compose tests.
android

## Public properties

### activity

android Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val activity: A?
```

Returns the current activity of type `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/AndroidComposeUiTest` used in this `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/ComposeUiTest`. If no such activity is available, for example if you've navigated to a different activity and the original host has now been destroyed, this will return `null`.

Note that you should never hold on to a reference to the Activity, always use `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/AndroidComposeUiTest#activity()` to interact with the Activity.