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

ComposeTestRuleKt

public final class ComposeTestRuleKt


Summary

Public methods

static final @NonNull ComposeContentTestRule

Factory method to provide an implementation of ComposeContentTestRule.

static final @NonNull ComposeContentTestRule

Factory method to provide an implementation of ComposeContentTestRule.

Public methods

createComposeRule

public static final @NonNull ComposeContentTestRule createComposeRule()

Factory method to provide an implementation of ComposeContentTestRule.

This method is useful for tests in compose libraries where it is irrelevant where the compose content is hosted (e.g. an Activity on Android). Such tests typically set compose content themselves via setContent and only instrument and assert that content.

For Android this will use the default Activity (android.app.Activity). You need to add a reference to this activity into the manifest file of the corresponding tests (usually in androidTest/AndroidManifest.xml). If your Android test requires a specific Activity to be launched, see createAndroidComposeRule.

createComposeRule

@ExperimentalTestApi
public static final @NonNull ComposeContentTestRule createComposeRule(@NonNull CoroutineContext effectContext)

Factory method to provide an implementation of ComposeContentTestRule.

This method is useful for tests in compose libraries where it is irrelevant where the compose content is hosted (e.g. an Activity on Android). Such tests typically set compose content themselves via setContent and only instrument and assert that content.

For Android this will use the default Activity (android.app.Activity). You need to add a reference to this activity into the manifest file of the corresponding tests (usually in androidTest/AndroidManifest.xml). If your Android test requires a specific Activity to be launched, see createAndroidComposeRule.

Parameters
@NonNull CoroutineContext effectContext

The CoroutineContext used to run the composition. The context for LaunchedEffects and rememberCoroutineScope will be derived from this context.