# ComposeContentTestRule

Artifact: [androidx.compose.ui:ui-test-junit4](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/test/junit4/ComposeTestRule.jvmAndAndroid.kt+class:androidx.compose.ui.test.junit4.ComposeContentTestRule) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Android/JVM
- android

  ```
  interface ComposeContentTestRule : ComposeTestRule
  ```
Known direct subclasses [AndroidComposeTestRule](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule` |   |

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule` that allows you to set content without the necessity to provide a host for the content. The host, such as an Activity, will be created by the test rule.

An instance of `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeContentTestRule` can be created with `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/package-summary#createComposeRule(kotlin.coroutines.CoroutineContext)`. If you need to specify which particular Activity is started on Android, you can use `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/package-summary#createAndroidComposeRule(kotlin.coroutines.CoroutineContext)`.

If you don't want any host to be started automatically by the test rule on Android, you can use `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/package-summary#createEmptyComposeRule(kotlin.coroutines.CoroutineContext)`. In such a case, you will have to create a host in your test and set the content using one of Compose UI's setters (like `https://developer.android.com/reference/kotlin/androidx/activity/compose/package-summary#(androidx.activity.ComponentActivity).setContent(androidx.compose.runtime.CompositionContext,kotlin.Function0)`).

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeContentTestRule#setContent(kotlin.Function0)(composable: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable @https://developer.android.com/reference/kotlin/androidx/compose/ui/UiComposable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Sets the given composable as a content of the current screen. | android |

### Inherited functions

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

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

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

Executes the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#runOnIdle(kotlin.Function0)` in the same way as `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#runOnUiThread(kotlin.Function0)` but `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#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/junit4/ComposeTestRule#runOnUiThread(kotlin.Function0)(action: () -> T)`

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

Executes the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#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/junit4/ComposeTestRule#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 `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#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/junit4/ComposeTestRule#waitUntil(kotlin.Long,kotlin.Function0)(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/junit4/ComposeTestRule#waitUntil(kotlin.Long,kotlin.Function0)` is satisfied.
android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#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/junit4/ComposeTestRule#waitUntil(kotlin.String,kotlin.Long,kotlin.Function0)` is satisfied.
android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#waitUntilAtLeastOneExists(androidx.compose.ui.test.SemanticsMatcher,kotlin.Long,kotlin.Boolean)(
matcher: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsMatcher,
timeoutMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html,
useUnmergedTree: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html
)`

Blocks until at least one node matches the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#waitUntilAtLeastOneExists(androidx.compose.ui.test.SemanticsMatcher,kotlin.Long,kotlin.Boolean)`.
android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#waitUntilDoesNotExist(androidx.compose.ui.test.SemanticsMatcher,kotlin.Long,kotlin.Boolean)(
matcher: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsMatcher,
timeoutMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html,
useUnmergedTree: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html
)`

Blocks until no nodes match the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#waitUntilDoesNotExist(androidx.compose.ui.test.SemanticsMatcher,kotlin.Long,kotlin.Boolean)`.
android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#waitUntilExactlyOneExists(androidx.compose.ui.test.SemanticsMatcher,kotlin.Long,kotlin.Boolean)(
matcher: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsMatcher,
timeoutMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html,
useUnmergedTree: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html
)`

Blocks until exactly one node matches the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#waitUntilExactlyOneExists(androidx.compose.ui.test.SemanticsMatcher,kotlin.Long,kotlin.Boolean)`.
android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#waitUntilNodeCount(androidx.compose.ui.test.SemanticsMatcher,kotlin.Int,kotlin.Long,kotlin.Boolean)(
matcher: https://developer.android.com/reference/kotlin/androidx/compose/ui/test/SemanticsMatcher,
count: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,
timeoutMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html,
useUnmergedTree: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html
)`

Blocks until the number of nodes matching the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#waitUntilNodeCount(androidx.compose.ui.test.SemanticsMatcher,kotlin.Int,kotlin.Long,kotlin.Boolean)` is equal to the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#waitUntilNodeCount(androidx.compose.ui.test.SemanticsMatcher,kotlin.Int,kotlin.Long,kotlin.Boolean)`.
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 From [org.junit.rules.TestRule](https://junit.org/junit4/javadoc/latest/org/junit/rules/TestRule.html) `https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html` `https://junit.org/junit4/javadoc/latest/org/junit/rules/TestRule.html#apply-org.junit.runners.model.Statement-org.junit.runner.Description-(p0: https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html, p1: https://junit.org/junit4/javadoc/latest/org/junit/runner/Description.html)` android

### Inherited properties

From [androidx.compose.ui.test.junit4.ComposeTestRule](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule) `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density` `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule#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/junit4/ComposeTestRule#mainClock()`

Clock that drives frames and recompositions in compose tests.
android

## Public functions

### setContent

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

```
fun setContent(composable: @Composable @UiComposable () -> Unit): Unit
```

Sets the given composable as a content of the current screen.

Use this in your tests to setup the UI content to be tested. This should be called exactly once per test.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if called more than once per test. |