androidx.ui.test

Classes

CollectedSizes

Small utility class to provide convenient assertion for width and height for some PxSize.

DisableTransitions

This rule will disable all Transition animations for the test.

SemanticsNodeInteraction

Represents a component with which one can interact with the hierarchy.

Top-level functions summary

Unit

Asserts no items found given a criteria, throws AssertionError otherwise.

ComposeTestRule
createComposeRule(disableTransitions: Boolean = false)

Factory method to provide implementation of ComposeTestRule.

SemanticsConfiguration
createFullSemantics(isEnabled: Boolean? = null, value: String? = null, toggleableState: ToggleableState? = null, inMutuallyExclusiveGroup: Boolean? = null, isSelected: Boolean? = null)

Ensures the created SemanticsConfiguration object doesn't have any default values set.

SemanticsNodeInteraction
find(selector: SemanticsConfiguration.() -> Boolean)

Finds a component that matches the given condition.

List<SemanticsNodeInteraction>

List<SemanticsNodeInteraction>
findAllByTag(testTag: String)

Finds all components identified by the given tag.

SemanticsNodeInteraction
findByTag(testTag: String)

Finds a component identified by the given tag.

SemanticsNodeInteraction
findByText(text: String, ignoreCase: Boolean = false)

Finds a component by the given text.

Boolean

Top-level properties summary

DpConstraints

Constant to emulate very big but finite constraints

Extension functions summary

For kotlin.collections.List
List<SemanticsNodeInteraction>

Asserts that given a list of components, its size is equal to the passed in size.

For SemanticsConfiguration
Unit

SemanticsConfiguration

Returns a (mutated) copy of the original SemanticsConfiguration object.

For SemanticsNodeInteraction
SemanticsNodeInteraction

Asserts that the current component has a click action.

SemanticsNodeInteraction

Asserts that the current component doesn't have a click action.

SemanticsNodeInteraction

Asserts that the current component is displayed.

SemanticsNodeInteraction

Asserts that current component is hidden.

SemanticsNodeInteraction

Asserts the component is in a mutually exclusive group.

SemanticsNodeInteraction

Asserts that the current component is not displayed.

SemanticsNodeInteraction

Asserts that the current component is unchecked.

SemanticsNodeInteraction

Asserts that the current component is checked.

SemanticsNodeInteraction

Asserts that the current component is selected.

SemanticsNodeInteraction

Asserts that the current component is unselected.

SemanticsNodeInteraction

Asserts that current component is visible.

Unit

Asserts that the component isn't part of the component tree anymore.

SemanticsNodeInteraction

Asserts that the semantics of the component are the same as the given semantics.

SemanticsNodeInteraction

Asserts the component's value equals the given value.

SemanticsNodeInteraction

Performs a click action on the given component.

SemanticsNodeInteraction

Scrolls to a component using SemanticsActions.

Unit

Unit

Verifies that the provided condition is true.

Unit

Verifies that the provided condition is true on all parent semantics nodes.

For ComposeExecutionControl
Unit

Performs recomposition and asserts that there were some pending changes.

Unit

Asserts that last recomposition had some changes.

Unit

Asserts that last recomposition had no some changes.

Unit

Assert that the underlying view under test has a positive size.

Unit

Performs recomposition and asserts that there were some pending changes.

Unit

Performs the given amount of frames and asserts that there are no changes pending afterwards.

Int

Runs frames until there are no changes pending.

Unit

Performs recomposition and asserts that there were some pending changes.

For ComposeTestRule
CollectedSizes
ComposeTestRule.setContentAndCollectSizes(parentConstraints: DpConstraints = BigTestConstraints, children: () -> Unit)

Set content as with ComposeTestRule.setContent, but return CollectedSizes to assert width and height of this content

PxSize
ComposeTestRule.setContentAndGetPixelSize(parentConstraints: DpConstraints = BigTestConstraints, performSetContent: (() -> Unit) -> Unit = { setContent(it) }, children: () -> Unit)

Set content as with ComposeTestRule.setContent, but return sizes of this content

For ComposeBenchmarkScope
Unit

Sets up the content.

Extension properties summary

Top-level functions

assertDoesNotExist

fun assertDoesNotExist(selector: SemanticsConfiguration.() -> Boolean): Unit

Asserts no items found given a criteria, throws AssertionError otherwise.

createComposeRule

fun createComposeRule(disableTransitions: Boolean = false): ComposeTestRule

Factory method to provide implementation of ComposeTestRule.

createFullSemantics

fun createFullSemantics(
    isEnabled: Boolean? = null,
    value: String? = null,
    toggleableState: ToggleableState? = null,
    inMutuallyExclusiveGroup: Boolean? = null,
    isSelected: Boolean? = null
): SemanticsConfiguration

Ensures the created SemanticsConfiguration object doesn't have any default values set. This intentionally enforces choosing every value in order to minimise possible unwanted side effects. Should be used to create initial default semantics for composables and afterwards SemanticsConfiguration.copyWith should be used to create a modified copy.

find

fun find(selector: SemanticsConfiguration.() -> Boolean): SemanticsNodeInteraction

Finds a component that matches the given condition. This tries to match exactly one element and throws AssertionError if more than one is matched.

For usage patterns see SemanticsNodeInteraction

findAll

fun findAll(selector: SemanticsConfiguration.() -> Boolean): List<SemanticsNodeInteraction>

findAllByTag

fun findAllByTag(testTag: String): List<SemanticsNodeInteraction>

Finds all components identified by the given tag.

For usage patterns see SemanticsNodeInteraction

findByTag

fun findByTag(testTag: String): SemanticsNodeInteraction

Finds a component identified by the given tag.

For usage patterns see SemanticsNodeInteraction

findByText

fun findByText(
    text: String,
    ignoreCase: Boolean = false
): SemanticsNodeInteraction

Finds a component by the given text.

For usage patterns see SemanticsNodeInteraction

waitForIdleCompose

fun waitForIdleCompose(): Boolean

Top-level properties

BigTestConstraints

val BigTestConstraints: DpConstraints

Constant to emulate very big but finite constraints

Extension functions

assertCountEquals

fun List<SemanticsNodeInteraction>.assertCountEquals(count: Int): List<SemanticsNodeInteraction>

Asserts that given a list of components, its size is equal to the passed in size.

assertEquals

fun SemanticsConfiguration.assertEquals(expected: SemanticsConfiguration): Unit

assertHasClickAction

fun SemanticsNodeInteraction.assertHasClickAction(): SemanticsNodeInteraction

Asserts that the current component has a click action.

Throws AssertionError if the component is doesn't have a click action.

assertHasNoClickAction

fun SemanticsNodeInteraction.assertHasNoClickAction(): SemanticsNodeInteraction

Asserts that the current component doesn't have a click action.

Throws AssertionError if the component has a click action.

assertHasPendingChanges

fun ComposeExecutionControl.assertHasPendingChanges(): Unit

Performs recomposition and asserts that there were some pending changes.

Exceptions
AssertionError if recomposition has no pending changes.

assertIsDisplayed

fun SemanticsNodeInteraction.assertIsDisplayed(): SemanticsNodeInteraction

Asserts that the current component is displayed. This function also calls assertIsVisible to check if it is visible from a Semantics perspective and afterwards checks if it's bounding rectangle is contained inside the closest layout node.

assertIsHidden

fun SemanticsNodeInteraction.assertIsHidden(): SemanticsNodeInteraction

Asserts that current component is hidden. This requires that the component actually exists in the hierarchy and is hidden. If you want to actually verify that the component does not exist at all, please use assertNoLongerExists

assertIsInMutuallyExclusiveGroup

fun SemanticsNodeInteraction.assertIsInMutuallyExclusiveGroup(): SemanticsNodeInteraction

Asserts the component is in a mutually exclusive group. This is used by radio groups to assert only one is selected at a given time. For further details please check SemanticsConfiguration.isInMutuallyExclusiveGroup.

assertIsNotDisplayed

fun SemanticsNodeInteraction.assertIsNotDisplayed(): SemanticsNodeInteraction

Asserts that the current component is not displayed. This function checks if it's bounding rectangle is not contained inside the closest layout node.

assertIsOff

fun SemanticsNodeInteraction.assertIsOff(): SemanticsNodeInteraction

Asserts that the current component is unchecked.

Throws AssertionError if the component is checked, indeterminate, or not toggleable.

assertIsOn

fun SemanticsNodeInteraction.assertIsOn(): SemanticsNodeInteraction

Asserts that the current component is checked.

Throws AssertionError if the component is not unchecked, indeterminate, or not toggleable.

assertIsSelected

fun SemanticsNodeInteraction.assertIsSelected(): SemanticsNodeInteraction

Asserts that the current component is selected.

Throws AssertionError if the component is unselected or not selectable.

assertIsUnselected

fun SemanticsNodeInteraction.assertIsUnselected(): SemanticsNodeInteraction

Asserts that the current component is unselected.

Throws AssertionError if the component is selected or not selectable.

assertIsVisible

fun SemanticsNodeInteraction.assertIsVisible(): SemanticsNodeInteraction

Asserts that current component is visible.

assertLastRecomposeHadChanges

fun ComposeExecutionControl.assertLastRecomposeHadChanges(): Unit

Asserts that last recomposition had some changes.

assertLastRecomposeHadNoChanges

fun ComposeExecutionControl.assertLastRecomposeHadNoChanges(): Unit

Asserts that last recomposition had no some changes.

assertMeasureSizeIsPositive

fun ComposeExecutionControl.assertMeasureSizeIsPositive(): Unit

Assert that the underlying view under test has a positive size.

Useful to assert that the test case has some content.

Exceptions
AssertionError if the underlying view has zero measured size.

assertNoLongerExists

fun SemanticsNodeInteraction.assertNoLongerExists(): Unit

Asserts that the component isn't part of the component tree anymore. If the component exists but is hidden use assertIsHidden instead.

assertNoPendingChanges

fun ComposeExecutionControl.assertNoPendingChanges(): Unit

Performs recomposition and asserts that there were some pending changes.

Exceptions
AssertionError if recomposition has pending changes.

assertSemanticsIsEqualTo

fun SemanticsNodeInteraction.assertSemanticsIsEqualTo(expectedProperties: SemanticsConfiguration): SemanticsNodeInteraction

Asserts that the semantics of the component are the same as the given semantics. For further details please check SemanticsConfiguration.assertEquals.

assertValueEquals

fun SemanticsNodeInteraction.assertValueEquals(value: String): SemanticsNodeInteraction

Asserts the component's value equals the given value. This is used by CircularProgressIndicator to check progress. For further details please check SemanticsConfiguration.accessibilityValue. Throws AssertionError if the node's value is not equal to value, or if the node has no value

copyWith

fun SemanticsConfiguration.copyWith(diff: SemanticsConfiguration.() -> Unit): SemanticsConfiguration

Returns a (mutated) copy of the original SemanticsConfiguration object. Uses SemanticsPropertiesBuilder as an intermediate (mutable) representation of SemanticsConfiguration

doClick

fun SemanticsNodeInteraction.doClick(): SemanticsNodeInteraction

Performs a click action on the given component.

doFramesAssertAllHadChangesExceptLastOne

fun ComposeExecutionControl.doFramesAssertAllHadChangesExceptLastOne(numberOfFramesToBeStable: Int): Unit

Performs the given amount of frames and asserts that there are no changes pending afterwards. Also asserts that all the frames (except the last one) had changes to recompose.

Exceptions
AssertionError if any frame before numberOfFramesToBeStable frame had no pending changes or the last frame had pending changes.

doFramesUntilNoChangesPending

fun ComposeExecutionControl.doFramesUntilNoChangesPending(maxAmountOfFrames: Int = 10): Int

Runs frames until there are no changes pending.

Parameters
maxAmountOfFrames: Int = 10 Max amount of frames to perform before giving up and throwing exception.
Exceptions
AssertionError if there are still pending changes after maxAmountOfFrames executed.

doScrollTo

fun SemanticsNodeInteraction.doScrollTo(): SemanticsNodeInteraction

Scrolls to a component using SemanticsActions. It first identifies a parent component with a Semantics ScrollTo action, then it retrieves the location of the current element and computes the relative coordinates that will be used by the scroller.

Throws AssertionError if there is no parent component with ScrollTo SemanticsAction, the current semantics component doesn't have a bounding rectangle set or if a layout node used to compute the relative coordinates to be fed to the ScrollTo action can't be found.

dumpSemantics

fun SemanticsNodeInteraction.dumpSemantics(consumer: (String) -> Unit): Unit

recomposeAssertHadChanges

fun ComposeExecutionControl.recomposeAssertHadChanges(): Unit

Performs recomposition and asserts that there were some pending changes.

Exceptions
AssertionError if last recomposition had no changes.

setContentAndCollectSizes

fun ComposeTestRule.setContentAndCollectSizes(
    parentConstraints: DpConstraints = BigTestConstraints,
    children: () -> Unit
): CollectedSizes

Set content as with ComposeTestRule.setContent, but return CollectedSizes to assert width and height of this content

Parameters
parentConstraints: DpConstraints = BigTestConstraints desired parent constraints for content
children: () -> Unit content to set

setContentAndGetPixelSize

fun ComposeTestRule.setContentAndGetPixelSize(
    parentConstraints: DpConstraints = BigTestConstraints,
    performSetContent: (() -> Unit) -> Unit = { setContent(it) },
    children: () -> Unit
): PxSize

Set content as with ComposeTestRule.setContent, but return sizes of this content

Parameters
parentConstraints: DpConstraints = BigTestConstraints desired parent constraints for content
performSetContent: (() -> Unit) -> Unit = { setContent(it) } lambda that should be performed to set content. Defaults to ComposeTestRule.setContent and usually don't need to be changed
children: () -> Unit content to set

setupContent

fun <T> ComposeBenchmarkScope<T>.setupContent(): Unit

Sets up the content. This is by default called by first invocation of ComposeBenchmarkScope.doFrame.

If you want to call this multiple times, make sure you call ComposeBenchmarkScope.disposeContent in between.

verify

fun SemanticsNodeInteraction.verify(
    assertionMessage: (SemanticsConfiguration) -> String,
    condition: (SemanticsConfiguration) -> Boolean
): Unit

Verifies that the provided condition is true. Throws AssertionError if it is not.

verifyHierarchy

fun SemanticsNodeInteraction.verifyHierarchy(
    assertionMessage: (SemanticsConfiguration) -> String,
    condition: (SemanticsConfiguration) -> Boolean
): Unit

Verifies that the provided condition is true on all parent semantics nodes. Throws AssertionError if it is not.

Extension properties

hasClickAction

val SemanticsConfiguration.hasClickAction: Boolean

hasScrollAction

val SemanticsConfiguration.hasScrollAction: Boolean

isInMutuallyExclusiveGroup

val SemanticsConfiguration.isInMutuallyExclusiveGroup: Boolean

Verifies that a component is in a mutually exclusive group - that is, that FoundationSemanticsProperties.InMutuallyExclusiveGroup is set to true

isToggleable

val SemanticsConfiguration.isToggleable: Boolean

Verifies that a component is checkable.