Google berkomitmen untuk mendorong terwujudnya keadilan ras bagi komunitas Kulit Hitam. Lihat caranya.

ComposeTestRule

interface ComposeTestRule
androidx.ui.test.ComposeTestRule

Enables to run tests of individual composables without having to do manual setup. Normally this rule is obtained by using createComposeRule factory that provides proper implementation (depending if running host side or Android side).

Summary

Public methods
open SemanticsNodeInteractionCollection
onAllNodes(matcher: SemanticsMatcher, useUnmergedTree: Boolean = false)

Finds all semantics nodes that match the given condition.

open SemanticsNodeInteraction
onNode(matcher: SemanticsMatcher, useUnmergedTree: Boolean = false)

Finds a semantics node that matches the given condition.

abstract T
runOnIdle(action: () -> T)

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

abstract T
runOnUiThread(action: () -> T)

Runs the given action on the UI thread.

abstract Unit

Waits for compose to be idle.

Extension functions
From androidx.ui.test
SemanticsNodeInteractionCollection
ComposeTestRule.onAllNodesWithLabel(label: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds all semantics nodes with the given label as AccessibilityLabel.

SemanticsNodeInteractionCollection
ComposeTestRule.onAllNodesWithTag(testTag: String, useUnmergedTree: Boolean = false)

Finds all semantics nodes identified by the given tag.

SemanticsNodeInteractionCollection
ComposeTestRule.onAllNodesWithText(text: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds all semantics nodes with the given text.

SemanticsNodeInteraction
ComposeTestRule.onNodeWithLabel(label: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds a semantics node with the given label as its accessibilityLabel.

SemanticsNodeInteraction
ComposeTestRule.onNodeWithSubstring(text: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds a semantics node with text that contains the given substring.

SemanticsNodeInteraction
ComposeTestRule.onNodeWithTag(testTag: String, useUnmergedTree: Boolean = false)

Finds a semantics node identified by the given tag.

SemanticsNodeInteraction
ComposeTestRule.onNodeWithText(text: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds a semantincs node with the given text.

SemanticsNodeInteraction
ComposeTestRule.onRoot(useUnmergedTree: Boolean = false)

Finds the root semantics node of the Compose tree.

Properties
abstract Density

Current device screen's density.

abstract IntSize

Current device display's size.

Public methods

onAllNodes

open fun onAllNodes(
    matcher: SemanticsMatcher,
    useUnmergedTree: Boolean = false
): SemanticsNodeInteractionCollection

Finds all semantics nodes that match the given condition.

If you are working with elements that are not supposed to occur multiple times use onNode instead.

For usage patterns and semantics concepts see SemanticsNodeInteraction

Parameters
useUnmergedTree: Boolean = false Find within merged composables like Buttons.

See Also

onNode

open fun onNode(
    matcher: SemanticsMatcher,
    useUnmergedTree: Boolean = false
): SemanticsNodeInteraction

Finds a semantics node that matches the given condition.

Any subsequent operation on its result will expect exactly one element found (unless SemanticsNodeInteraction.assertDoesNotExist is used) and will throw AssertionError if none or more than one element is found.

For usage patterns and semantics concepts see SemanticsNodeInteraction

Parameters
useUnmergedTree: Boolean = false Find within merged composables like Buttons.

See Also

runOnIdle

abstract fun <T> runOnIdle(action: () -> T): T

Executes the given action in the same way as runOnUiThread but also makes sure Compose is idle before executing it. This is great place for doing your assertions on shared variables.

This method is blocking until the action is complete.

runOnUiThread

abstract fun <T> runOnUiThread(action: () -> T): T

Runs the given action on the UI thread.

This method is blocking until the action is complete.

waitForIdle

abstract fun waitForIdle(): Unit

Waits for compose to be idle.

This is a blocking call. Returns only after compose is idle.

Can crash in case there is a time out. This is not supposed to be handled as it surfaces only in incorrect tests.

Properties

density

abstract val density: Density

Current device screen's density.

displaySize

abstract val displaySize: IntSize

Current device display's size.