ComposeContentTestRule


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 ComponentActivity .setContent).

Summary

Public functions

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

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

android

Inherited functions

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

Suspends until compose is idle.

android
Unit

Registers an IdlingResource in this test.

android
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.

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

Runs the given action on the UI thread.

android
Unit

Unregisters an IdlingResource from this test.

android
Unit

Waits for compose to be idle.

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

Blocks until the given condition is satisfied.

android
open Unit
waitUntil(
    conditionDescription: String,
    timeoutMillis: Long,
    condition: () -> Boolean
)

Blocks until the given condition is satisfied.

android
Unit

Blocks until at least one node matches the given matcher.

android
Unit

Blocks until no nodes match the given matcher.

android
Unit

Blocks until exactly one node matches the given matcher.

android
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.

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

Finds all semantics nodes that match the given condition.

android
SemanticsNodeInteraction
onNode(matcher: SemanticsMatcher, useUnmergedTree: Boolean)

Finds a semantics node that matches the given condition.

android
From org.junit.rules.TestRule
Statement
android

Inherited properties

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

Current device screen's density.

android
MainTestClock

Clock that drives frames and recompositions in compose tests.

android

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.