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

ComposeContentTestRule

public interface ComposeContentTestRule extends 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 methods

abstract void
setContent(@Composable @NonNull Function0<Unit> composable)

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

Inherited methods

From androidx.compose.ui.test.junit4.ComposeTestRule
abstract void

Suspends until compose is idle.

abstract @NonNull Density

Current device screen's density.

abstract @NonNull MainTestClock

Clock that drives frames and recompositions in compose tests.

abstract void

Registers an IdlingResource in this test.

abstract @NonNull T
<T extends Object> runOnIdle(@NonNull Function0<@NonNull T> action)

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

abstract @NonNull T
<T extends Object> runOnUiThread(@NonNull Function0<@NonNull T> action)

Runs the given action on the UI thread.

abstract void

Unregisters an IdlingResource from this test.

abstract void

Waits for compose to be idle.

abstract void
waitUntil(
    long timeoutMillis,
    @NonNull Function0<@NonNull Boolean> condition
)

Blocks until the given condition is satisfied.

abstract void
@ExperimentalTestApi
waitUntilAtLeastOneExists(
    @NonNull SemanticsMatcher matcher,
    long timeoutMillis
)

Blocks until at least one node matches the given matcher.

abstract void
@ExperimentalTestApi
waitUntilDoesNotExist(
    @NonNull SemanticsMatcher matcher,
    long timeoutMillis
)

Blocks until no nodes match the given matcher.

abstract void
@ExperimentalTestApi
waitUntilExactlyOneExists(
    @NonNull SemanticsMatcher matcher,
    long timeoutMillis
)

Blocks until exactly one node matches the given matcher.

abstract void
@ExperimentalTestApi
waitUntilNodeCount(
    @NonNull SemanticsMatcher matcher,
    int count,
    long timeoutMillis
)

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

From androidx.compose.ui.test.SemanticsNodeInteractionsProvider
abstract @NonNull SemanticsNodeInteractionCollection
onAllNodes(@NonNull SemanticsMatcher matcher, boolean useUnmergedTree)

Finds all semantics nodes that match the given condition.

abstract @NonNull SemanticsNodeInteraction
onNode(@NonNull SemanticsMatcher matcher, boolean useUnmergedTree)

Finds a semantics node that matches the given condition.

From org.junit.rules.TestRule

Public methods

setContent

abstract void setContent(@Composable @NonNull Function0<Unit> composable)

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.