{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ComposeContentTestRule

interface ComposeContentTestRule : ComposeTestRule

Known direct subclasses

A 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 ComposeContentTestRule can be created with createComposeRule. If you need to specify which particular Activity is started on Android, you can use createAndroidComposeRule.

If you don't want any host to be started automatically by the test rule on Android, you can use createEmptyComposeRule. 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 androidx.activity.compose.setContent).

Summary

Public functions

Unit
setContent(composable: @Composable () -> Unit)

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

Inherited functions

From androidx.compose.ui.test.junit4.ComposeTestRule
suspend Unit

Suspends until compose is idle.

Unit

Registers an IdlingResource in this test.

T
<T : Any?> runOnIdle(action: () -> T)

Executes the given action in the same way as runOnUiThread but also makes sure Compose is idle before executing it.

T
<T : Any?> runOnUiThread(action: () -> T)

Runs the given action on the UI thread.

Unit

Unregisters an IdlingResource from this test.

Unit

Waits for compose to be idle.

Unit
waitUntil(timeoutMillis: Long, condition: () -> Boolean)

Blocks until the given condition is satisfied.

Unit

Blocks until at least one node matches the given matcher.

Unit

Blocks until no nodes match the given matcher.

Unit

Blocks until exactly one node matches the given matcher.

Unit
@ExperimentalTestApi
waitUntilNodeCount(
    matcher: SemanticsMatcher,
    count: Int,
    timeoutMillis: Long
)

Blocks until the number of nodes matching the given matcher is equal to the given count.

From androidx.compose.ui.test.SemanticsNodeInteractionsProvider
SemanticsNodeInteractionCollection
onAllNodes(matcher: SemanticsMatcher, useUnmergedTree: Boolean)

Finds all semantics nodes that match the given condition.

SemanticsNodeInteraction
onNode(matcher: SemanticsMatcher, useUnmergedTree: Boolean)

Finds a semantics node that matches the given condition.

From org.junit.rules.TestRule

Inherited properties

From androidx.compose.ui.test.junit4.ComposeTestRule
Density

Current device screen's density.

MainTestClock

Clock that drives frames and recompositions in compose tests.

Public functions

setContent

fun setContent(composable: @Composable () -> 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
kotlin.IllegalStateException

if called more than once per test.