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

AndroidComposeTestRuleKt

public final class AndroidComposeTestRuleKt


Summary

Public methods

static final @NonNull AndroidComposeTestRule<@NonNull <Error class: unknown class><@NonNull A>, @NonNull A>

Factory method to provide android specific implementation of createComposeRule, for a given activity class type A.

static final @NonNull AndroidComposeTestRule<@NonNull <Error class: unknown class><@NonNull A>, @NonNull A>
<A extends ComponentActivity> createAndroidComposeRule(
    @NonNull Class<@NonNull A> activityClass
)

Factory method to provide android specific implementation of createComposeRule, for a given activityClass.

static final @NonNull AndroidComposeTestRule<@NonNull <Error class: unknown class><@NonNull A>, @NonNull A>

Factory method to provide android specific implementation of createComposeRule, for a given activity class type A.

static final @NonNull AndroidComposeTestRule<@NonNull <Error class: unknown class><@NonNull A>, @NonNull A>
@ExperimentalTestApi
<A extends ComponentActivity> createAndroidComposeRule(
    @NonNull Class<@NonNull A> activityClass,
    @NonNull CoroutineContext effectContext
)

Factory method to provide android specific implementation of createComposeRule, for a given activityClass.

static final @NonNull ComposeContentTestRule
static final @NonNull ComposeContentTestRule
static final @NonNull ComposeTestRule

Factory method to provide an implementation of ComposeTestRule that doesn't create a compose host for you in which you can set content.

static final @NonNull ComposeTestRule

Factory method to provide an implementation of ComposeTestRule that doesn't create a compose host for you in which you can set content.

Public methods

createAndroidComposeRule

public static final @NonNull AndroidComposeTestRule<@NonNull <Error class: unknown class><@NonNull A>, @NonNull A> <A extends ComponentActivity> createAndroidComposeRule()

Factory method to provide android specific implementation of createComposeRule, for a given activity class type A.

This method is useful for tests that require a custom Activity. This is usually the case for tests where the compose content is set by that Activity, instead of via the test rule's setContent. Make sure that you add the provided activity into your app's manifest file (usually in main/AndroidManifest.xml).

This creates a test rule that is using ActivityScenarioRule as the activity launcher. If you would like to use a different one you can create AndroidComposeTestRule directly and supply it with your own launcher.

If your test doesn't require a specific Activity, use createComposeRule instead.

createAndroidComposeRule

public static final @NonNull AndroidComposeTestRule<@NonNull <Error class: unknown class><@NonNull A>, @NonNull A> <A extends ComponentActivity> createAndroidComposeRule(
    @NonNull Class<@NonNull A> activityClass
)

Factory method to provide android specific implementation of createComposeRule, for a given activityClass.

This method is useful for tests that require a custom Activity. This is usually the case for tests where the compose content is set by that Activity, instead of via the test rule's setContent. Make sure that you add the provided activity into your app's manifest file (usually in main/AndroidManifest.xml).

This creates a test rule that is using ActivityScenarioRule as the activity launcher. If you would like to use a different one you can create AndroidComposeTestRule directly and supply it with your own launcher.

If your test doesn't require a specific Activity, use createComposeRule instead.

createAndroidComposeRule

@ExperimentalTestApi
public static final @NonNull AndroidComposeTestRule<@NonNull <Error class: unknown class><@NonNull A>, @NonNull A> <A extends ComponentActivity> createAndroidComposeRule(
    @NonNull CoroutineContext effectContext
)

Factory method to provide android specific implementation of createComposeRule, for a given activity class type A.

This method is useful for tests that require a custom Activity. This is usually the case for tests where the compose content is set by that Activity, instead of via the test rule's setContent. Make sure that you add the provided activity into your app's manifest file (usually in main/AndroidManifest.xml).

This creates a test rule that is using ActivityScenarioRule as the activity launcher. If you would like to use a different one you can create AndroidComposeTestRule directly and supply it with your own launcher.

If your test doesn't require a specific Activity, use createComposeRule instead.

createAndroidComposeRule

@ExperimentalTestApi
public static final @NonNull AndroidComposeTestRule<@NonNull <Error class: unknown class><@NonNull A>, @NonNull A> <A extends ComponentActivity> createAndroidComposeRule(
    @NonNull Class<@NonNull A> activityClass,
    @NonNull CoroutineContext effectContext
)

Factory method to provide android specific implementation of createComposeRule, for a given activityClass.

This method is useful for tests that require a custom Activity. This is usually the case for tests where the compose content is set by that Activity, instead of via the test rule's setContent. Make sure that you add the provided activity into your app's manifest file (usually in main/AndroidManifest.xml).

This creates a test rule that is using ActivityScenarioRule as the activity launcher. If you would like to use a different one you can create AndroidComposeTestRule directly and supply it with your own launcher.

If your test doesn't require a specific Activity, use createComposeRule instead.

createComposeRule

public static final @NonNull ComposeContentTestRule createComposeRule()

createComposeRule

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

createEmptyComposeRule

public static final @NonNull ComposeTestRule createEmptyComposeRule()

Factory method to provide an implementation of ComposeTestRule that doesn't create a compose host for you in which you can set content.

This method is useful for tests that need to create their own compose host during the test. The returned test rule will not create a host, and consequently does not provide a setContent method. To set content in tests using this rule, use the appropriate setContent methods from your compose host.

A typical use case on Android is when the test needs to launch an Activity (the compose host) after one or more dependencies have been injected.

createEmptyComposeRule

@ExperimentalTestApi
public static final @NonNull ComposeTestRule createEmptyComposeRule(@NonNull CoroutineContext effectContext)

Factory method to provide an implementation of ComposeTestRule that doesn't create a compose host for you in which you can set content.

This method is useful for tests that need to create their own compose host during the test. The returned test rule will not create a host, and consequently does not provide a setContent method. To set content in tests using this rule, use the appropriate setContent methods from your compose host.

A typical use case on Android is when the test needs to launch an Activity (the compose host) after one or more dependencies have been injected.

Parameters
@NonNull CoroutineContext effectContext

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